Merging r6519 through r6561 from trunk to ogl-es branch

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/branches/ogl-es@6562 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
cutealien 2023-10-16 21:17:56 +00:00
parent e9c494503d
commit 849336343d
169 changed files with 465 additions and 511 deletions

View File

@ -11,6 +11,8 @@ Changes in ogl-es (not yet released - will be merged with trunk at some point)
--------------------------
Changes in 1.9 (not yet released)
- TGA loader no longer reduces 24&32 bit TGA's with palettes to 16 bit. Thanks @erlehmann for report: https://irrlicht.sourceforge.io/forum/viewtopic.php?t=52925
- Fix compile error with OS X 10.10 SDK, bug #463. Thanks @Ryan Schmidt for report and patch.
- Optimize quaternion::rotationFromTo. Thanks @Robert Eisele for patch and proof (https://raw.org/proof/quaternion-from-two-vectors)
- Shader material example shows now how to pass material values.
In 1.8 we could still use gl_FrontMaterial, but that is no longer supported in shaders
@ -408,6 +410,29 @@ Changes in 1.9 (not yet released)
--------------------------
Changes in 1.8.6
- CXMeshFileLoader: fix buffer overreads with text format. Thanks @sfan5 for report and patch.
Patch (commit 6f4f7c4 to Minetest): https://github.com/minetest/irrlicht/commit/6f4f7c4d75c9d563e98d3936ed8bc6e248dc14a8
- Fix CB3DMeshFileLoader::readString. Prevent adding a character beyond file-end. Thanks @sfan5 for report and patch.
Original patch (commit 103ab16 to Minetest): https://github.com/minetest/irrlicht/commit/103ab16679a42cb1bfa4cc4e6316195ec2d139b6
- CB3DMeshFileLoader: add some bounds checks. Thanks @sfan5 for report and patch.
Original patch (commit 64688f4 to Minetest): https://github.com/minetest/irrlicht/commit/64688f449099246ec27eb013f58d72a0abb1c6e6
- TGA loader: Fix number overflow causing crashes. Thanks @sfan5 for fuzzing test.
- TGA loader: Fix several buffer overflows. Thanks @erlehmann for report and @sfan5 for fuzzing test: https://github.com/minetest/irrlicht/issues/236
- COBJMeshFilerLoder: prevent buffer overruns from loading files passing negative indices. Thanks @sfan5 fore report and patch.
Patch (commit 827710f to Minetest): https://github.com/minetest/irrlicht/commit/827710f74a615f53b2a1b0c539c58c2b6124f883
- COBJMeshFilerLoder: fix buffer overruns when loading empty face lines. Thanks @sfan5 fore report and patch.
Patch (commit 80e1609 to Minetest): https://github.com/minetest/irrlicht/commit/80e160935d3c2677344b0968c2690f63083a98dd (partially applied)
- CObjMeshFileLoader: Backport fixes from trunk to avoid unnecessary memory allocations (speedup)
- CObjMeshFileLoader: Backport fixes from trunk to avoid some buffer overruns
- CImageLoaderBMP: Fix handling 4 bit RLE encoding. Thanks @sfan5 finding first bug and reporting (had some more)
- CImageLoaderBMP: add bound checks to RLE decompression. Thanks @sfan5 for report and patch
Patch (commit 4506d23 to Minetest): https://github.com/minetest/irrlicht/commit/4506d23dc3fa48332b5ca6c05633aebdbac673be
- CImageLoaderBMP: check bitmap data against required size. Thanks @sfan5 for report and patch
Report: https://irrlicht.sourceforge.io/forum/viewtopic.php?p=307195
Patch (commit 028cb8d to Minetest): https://github.com/minetest/irrlicht/commit/028cb8dbed8266264a5804108191f56e238db1bc
- Fix OSX 10.9X build problem related to NSApplication setDelegate calls getting casted to wrong class (Bug #462 and also fixing older Bug #297)
Thanks @Ryan Schmidt for bug report and patch.
- Backport: Fix compiling for Apple silicon (Bugs #452 and #461). Thanks @Ryan Schmidt for bug report and updated patch.
- Fix compiling on OSX with case-sensitive filesystems: IrrFramework-Info.plist now always starting with upper-case.
Thanks @Ryan Schmidt for bug report and patch.
- Fix: The build-in libpng now uses same zlib headers as rest of Irrlicht.

View File

@ -734,7 +734,7 @@ void CQuake3EventHandler::CreateGUI()
gui.Tesselation->setMax ( 12 );
gui.Tesselation->setSmallStep ( 1 );
gui.Tesselation->setLargeStep ( 1 );
gui.Tesselation->setPos ( Game->loadParam.patchTesselation );
gui.Tesselation->setPos ( Game->loadParam.patchTessellation );
gui.Tesselation->setToolTipText ( L"How smooth should curved surfaces be rendered" );
gui.Collision = env->addCheckBox ( true, rect<s32>( dim.Width - 400, 150, dim.Width - 300, 166 ), gui.Window,-1, L"Collision" );
@ -1381,7 +1381,7 @@ bool CQuake3EventHandler::OnEvent(const SEvent& eve)
else
if ( eve.GUIEvent.Caller == gui.Tesselation && eve.GUIEvent.EventType == gui::EGET_SCROLL_BAR_CHANGED )
{
Game->loadParam.patchTesselation = gui.Tesselation->getPos ();
Game->loadParam.patchTessellation = gui.Tesselation->getPos ();
}
else
if ( eve.GUIEvent.Caller == gui.Gamma && eve.GUIEvent.EventType == gui::EGET_SCROLL_BAR_CHANGED )

View File

@ -5,7 +5,6 @@
#ifndef IRR_I_ANIMATED_MESH_H_INCLUDED
#define IRR_I_ANIMATED_MESH_H_INCLUDED
#include "aabbox3d.h"
#include "IMesh.h"
namespace irr

View File

@ -116,7 +116,7 @@ namespace scene
/** \return The aspect ratio of the camera. */
virtual f32 getAspectRatio() const =0;
//! Gets the field of view of the camera.
//! Gets the vertical field of view of the camera.
/** \return The field of view of the camera in radians. */
virtual f32 getFOV() const =0;
@ -135,7 +135,7 @@ namespace scene
\param aspect: New aspect ratio. */
virtual void setAspectRatio(f32 aspect) =0;
//! Sets the field of view (Default: PI / 2.5f)
//! Sets the vertical field of view (Default: PI / 2.5f)
/** Also changes projection matrix and resets IsOrthogonal flag.
\param fovy: New field of view in radians. */
virtual void setFOV(f32 fovy) =0;

View File

@ -7,7 +7,6 @@
#include "IMeshWriter.h"
#include "ISceneNode.h"
#include "IAnimatedMesh.h"
#include "SMaterial.h"
namespace irr

View File

@ -4,9 +4,8 @@
#ifndef IRR_I_GUI_IMAGE_LIST_H_INCLUDED
#define IRR_I_GUI_IMAGE_LIST_H_INCLUDED
#include "IGUIElement.h"
#include "rect.h"
#include "irrTypes.h"
#include "IReferenceCounted.h"
namespace irr
{

View File

@ -6,7 +6,6 @@
#define IRR_I_GUI_WINDOW_H_INCLUDED
#include "IGUIElement.h"
#include "EMessageBoxFlags.h"
namespace irr
{

View File

@ -10,7 +10,6 @@
#include "rect.h"
#include "SColor.h"
#include "irrAllocator.h"
#include <string.h>
namespace irr
{

View File

@ -6,7 +6,6 @@
#define IRR_I_IMAGE_WRITER_H_INCLUDED
#include "IReferenceCounted.h"
#include "irrString.h"
#include "coreutil.h"
namespace irr

View File

@ -6,7 +6,6 @@
#define IRR_I_INDEX_BUFFER_H_INCLUDED
#include "IReferenceCounted.h"
#include "irrArray.h"
#include "EHardwareBufferFlags.h"
#include "SVertexIndex.h"

View File

@ -8,7 +8,6 @@
#include "IReferenceCounted.h"
#include "path.h"
#include "IMeshTextureLoader.h"
#include "SVertexIndex.h"
namespace irr
{

View File

@ -7,7 +7,6 @@
#include "IReferenceCounted.h"
#include "irrArray.h"
#include "irrString.h"
#include "path.h"
#include "vector3d.h"
#include "dimension2d.h"

View File

@ -5,8 +5,6 @@
#ifndef IRR_I_SCENE_NODE_ANIMATOR_H_INCLUDED
#define IRR_I_SCENE_NODE_ANIMATOR_H_INCLUDED
#include "IReferenceCounted.h"
#include "vector3d.h"
#include "ESceneNodeAnimatorTypes.h"
#include "IAttributeExchangingObject.h"
#include "IAttributes.h"

View File

@ -6,7 +6,6 @@
#define IRR_I_SCENE_NODE_ANIMATOR_CAMERA_FPS_H_INCLUDED
#include "ISceneNodeAnimator.h"
#include "IEventReceiver.h"
#include "irrArray.h"
namespace irr

View File

@ -5,8 +5,6 @@
#ifndef IRR_I_SCENE_USER_DATA_SERIALIZER_H_INCLUDED
#define IRR_I_SCENE_USER_DATA_SERIALIZER_H_INCLUDED
#include "IReferenceCounted.h"
namespace irr
{
namespace io

View File

@ -6,9 +6,10 @@
#define IRR_I_SKINNED_MESH_H_INCLUDED
#include "irrArray.h"
#include "IBoneSceneNode.h"
#include "IAnimatedMesh.h"
#include "SSkinMeshBuffer.h"
#include "quaternion.h"
#include "irrString.h"
namespace irr
{

View File

@ -195,13 +195,17 @@ public:
//! Lock function.
/** Locks the Texture and returns a pointer to access the
pixels. After lock() has been called and all operations on the pixels
are done, you must call unlock().
Locks are not accumulating, hence one unlock will do for an arbitrary
number of previous locks. You should avoid locking different levels without
unlocking in between, though, because only the last level locked will be
unlocked.
are done, you must call unlock(). Locks are not accumulating, hence one
unlock will do for an arbitrary number of previous locks. You should avoid
locking different levels without unlocking in between, because only the
last level locked will be unlocked.
The size of the i-th mipmap level is defined as max(getSize().Width>>i,1)
and max(getSize().Height>>i,1)
and max(getSize().Height>>i,1).
Except for textures of EDT_SOFTWARE driver which returns data for
getOriginalSize(). Reason: Both original sized and modified sized textures are used
in that driver depending on whether the texture is used in 2d or 3d.
\param mode Specifies what kind of changes to the locked texture are
allowed. Unspecified behavior will arise if texture is written in read
only mode or read from in write only mode.

View File

@ -7,7 +7,6 @@
#include "SColor.h"
#include "matrix4.h"
#include "irrArray.h"
#include "irrMath.h"
#include "EMaterialTypes.h"
#include "EMaterialFlags.h"

View File

@ -8,9 +8,7 @@
#include "irrTypes.h"
#include "irrAllocator.h"
#include "irrMath.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
namespace irr
{

View File

@ -303,20 +303,33 @@ namespace core
\return Returns false if there is no inverse matrix. */
bool getInverse(CMatrix4<T>& out) const;
//! Tool function to build a perspective projection matrix
/** Mainly for use of the other perspective projection build functions.
But can also be used by users (can be useful if you don't work with matrices with T=f32).
\param sx: x scale factor (depth/half_width from clipped frustum planes parallel to the camera)
\param sy: y scale factor (depth/half_height from clipped frustum planes parallel to the camera)
\param zNear: Distance to near plane
\param zFar: Distance to far plane
param zClipFromZero: Clipping of z can be projected from 0 to w when true (D3D style) and from -w to w when false (OGL style)
\param zSign: 1 for left-handed projection matrix, -1 for right-handed projection matrix */
CMatrix4<T>& buildProjectionMatrixPerspectiveFov(T sx, T sy, T zNear, T zFar, bool zClipFromZero, T zSign);
//! Builds a right-handed perspective projection matrix based on a field of view
//\param zClipFromZero: Clipping of z can be projected from 0 to w when true (D3D style) and from -w to w when false (OGL style).
CMatrix4<T>& buildProjectionMatrixPerspectiveFovRH(f32 fieldOfViewRadians, f32 aspectRatio, f32 zNear, f32 zFar, bool zClipFromZero=true);
CMatrix4<T>& buildProjectionMatrixPerspectiveFovRH(f32 fieldOfViewRadiansY, f32 aspectRatio, f32 zNear, f32 zFar, bool zClipFromZero=true);
//! Builds a left-handed perspective projection matrix based on a field of view
CMatrix4<T>& buildProjectionMatrixPerspectiveFovLH(f32 fieldOfViewRadians, f32 aspectRatio, f32 zNear, f32 zFar, bool zClipFromZero=true);
CMatrix4<T>& buildProjectionMatrixPerspectiveFovLH(f32 fieldOfViewRadiansY, f32 aspectRatio, f32 zNear, f32 zFar, bool zClipFromZero=true);
//! Builds a left-handed perspective projection matrix based on a field of view, with far plane at infinity
CMatrix4<T>& buildProjectionMatrixPerspectiveFovInfinityLH(f32 fieldOfViewRadians, f32 aspectRatio, f32 zNear, f32 epsilon=0);
CMatrix4<T>& buildProjectionMatrixPerspectiveFovInfinityLH(f32 fieldOfViewRadiansY, f32 aspectRatio, f32 zNear, f32 epsilon=0);
//! Builds a right-handed perspective projection matrix.
CMatrix4<T>& buildProjectionMatrixPerspectiveRH(f32 widthOfViewVolume, f32 heightOfViewVolume, f32 zNear, f32 zFar, bool zClipFromZero=true);
//! Builds a left-handed perspective projection matrix.
//\param widthOfViewVolume: width of clipped near frustum plane
//\param heightOfViewVolume: height of clipped near frustum plane
CMatrix4<T>& buildProjectionMatrixPerspectiveLH(f32 widthOfViewVolume, f32 heightOfViewVolume, f32 zNear, f32 zFar, bool zClipFromZero=true);
//! Builds a left-handed orthogonal projection matrix.
@ -1568,102 +1581,70 @@ namespace core
}
// Builds a right-handed perspective projection matrix based on a field of view
// Builds a perspective projection matrix
template <class T>
inline CMatrix4<T>& CMatrix4<T>::buildProjectionMatrixPerspectiveFovRH(
f32 fieldOfViewRadians, f32 aspectRatio, f32 zNear, f32 zFar, bool zClipFromZero)
inline CMatrix4<T>& CMatrix4<T>::buildProjectionMatrixPerspectiveFov(T sx, T sy, T zNear, T zFar, bool zClipFromZero, T zSign)
{
const f64 h = reciprocal(tan(fieldOfViewRadians*0.5));
IRR_DEBUG_BREAK_IF(aspectRatio==0.f); //divide by zero
const T w = static_cast<T>(h / aspectRatio);
IRR_DEBUG_BREAK_IF(zNear==zFar); //divide by zero
M[0] = w;
M[0] = sx;
M[1] = 0;
M[2] = 0;
M[3] = 0;
M[4] = 0;
M[5] = (T)h;
M[5] = sy;
M[6] = 0;
M[7] = 0;
M[8] = 0;
M[9] = 0;
//M[10]
M[11] = -1;
//M[10] below
M[11] = zSign;
M[12] = 0;
M[13] = 0;
//M[14]
//M[14] below
M[15] = 0;
if ( zClipFromZero ) // DirectX version
{
M[10] = (T)(zFar/(zNear-zFar));
M[10] = zSign*zFar/(zFar-zNear);
M[14] = (T)(zNear*zFar/(zNear-zFar));
}
else // OpenGL version
{
M[10] = (T)((zFar+zNear)/(zNear-zFar));
M[10] = zSign*(zFar+zNear)/(zFar-zNear);
M[14] = (T)(2.0f*zNear*zFar/(zNear-zFar));
}
#if defined ( USE_MATRIX_TEST )
definitelyIdentityMatrix=false;
#endif
#if defined ( USE_MATRIX_TEST )
definitelyIdentityMatrix=false;
#endif
return *this;
}
// Builds a right-handed perspective projection matrix based on a field of view
template <class T>
inline CMatrix4<T>& CMatrix4<T>::buildProjectionMatrixPerspectiveFovRH(
f32 fieldOfViewRadians, f32 aspectRatio, f32 zNear, f32 zFar, bool zClipFromZero)
{
const f64 sy = reciprocal(tan(fieldOfViewRadians*0.5));
IRR_DEBUG_BREAK_IF(aspectRatio==0.f); //divide by zero
const T sx = static_cast<T>(sy / aspectRatio);
return buildProjectionMatrixPerspectiveFov(sx, static_cast<T>(sy), zNear, zFar, zClipFromZero, (T)-1);
}
// Builds a left-handed perspective projection matrix based on a field of view
template <class T>
inline CMatrix4<T>& CMatrix4<T>::buildProjectionMatrixPerspectiveFovLH(
f32 fieldOfViewRadians, f32 aspectRatio, f32 zNear, f32 zFar, bool zClipFromZero)
{
const f64 h = reciprocal(tan(fieldOfViewRadians*0.5));
const f64 sy = reciprocal(tan(fieldOfViewRadians*0.5));
IRR_DEBUG_BREAK_IF(aspectRatio==0.f); //divide by zero
const T w = static_cast<T>(h / aspectRatio);
IRR_DEBUG_BREAK_IF(zNear==zFar); //divide by zero
M[0] = w;
M[1] = 0;
M[2] = 0;
M[3] = 0;
M[4] = 0;
M[5] = (T)h;
M[6] = 0;
M[7] = 0;
M[8] = 0;
M[9] = 0;
//M[10]
M[11] = 1;
M[12] = 0;
M[13] = 0;
//M[14]
M[15] = 0;
if ( zClipFromZero ) // DirectX version
{
M[10] = (T)(zFar/(zFar-zNear));
M[14] = (T)(-zNear*zFar/(zFar-zNear));
}
else // OpenGL version
{
M[10] = (T)((zFar+zNear)/(zFar-zNear));
M[14] = (T)(2.0f*zNear*zFar/(zNear-zFar));
}
#if defined ( USE_MATRIX_TEST )
definitelyIdentityMatrix=false;
#endif
return *this;
const T sx = static_cast<T>(sy / aspectRatio);
return buildProjectionMatrixPerspectiveFov(sx, static_cast<T>(sy), zNear, zFar, zClipFromZero, (T)1);
}
// Builds a left-handed perspective projection matrix based on a field of view, with far plane culling at infinity
template <class T>
inline CMatrix4<T>& CMatrix4<T>::buildProjectionMatrixPerspectiveFovInfinityLH(
@ -1791,7 +1772,6 @@ namespace core
return *this;
}
// Builds a right-handed perspective projection matrix.
template <class T>
inline CMatrix4<T>& CMatrix4<T>::buildProjectionMatrixPerspectiveRH(
@ -1799,45 +1779,11 @@ namespace core
{
IRR_DEBUG_BREAK_IF(widthOfViewVolume==0.f); //divide by zero
IRR_DEBUG_BREAK_IF(heightOfViewVolume==0.f); //divide by zero
IRR_DEBUG_BREAK_IF(zNear==zFar); //divide by zero
M[0] = (T)(2*zNear/widthOfViewVolume);
M[1] = 0;
M[2] = 0;
M[3] = 0;
M[4] = 0;
M[5] = (T)(2*zNear/heightOfViewVolume);
M[6] = 0;
M[7] = 0;
M[8] = 0;
M[9] = 0;
//M[10]
M[11] = -1;
M[12] = 0;
M[13] = 0;
//M[14]
M[15] = 0;
if ( zClipFromZero ) // DirectX version
{
M[10] = (T)(zFar/(zNear-zFar));
M[14] = (T)(zNear*zFar/(zNear-zFar));
}
else // OpenGL version
{
M[10] = (T)((zFar+zNear)/(zNear-zFar));
M[14] = (T)(2.0f*zNear*zFar/(zNear-zFar));
}
#if defined ( USE_MATRIX_TEST )
definitelyIdentityMatrix=false;
#endif
return *this;
const T sx = (T)(2*zNear/widthOfViewVolume);
const T sy = (T)(2*zNear/heightOfViewVolume);
return buildProjectionMatrixPerspectiveFov(sx, sy, zNear, zFar, zClipFromZero, (T)-1);
}
// Builds a left-handed perspective projection matrix.
template <class T>
inline CMatrix4<T>& CMatrix4<T>::buildProjectionMatrixPerspectiveLH(
@ -1845,42 +1791,10 @@ namespace core
{
IRR_DEBUG_BREAK_IF(widthOfViewVolume==0.f); //divide by zero
IRR_DEBUG_BREAK_IF(heightOfViewVolume==0.f); //divide by zero
IRR_DEBUG_BREAK_IF(zNear==zFar); //divide by zero
M[0] = (T)(2*zNear/widthOfViewVolume);
M[1] = 0;
M[2] = 0;
M[3] = 0;
const T sx = (T)(2*zNear/widthOfViewVolume);
const T sy = (T)(2*zNear/heightOfViewVolume);
M[4] = 0;
M[5] = (T)(2*zNear/heightOfViewVolume);
M[6] = 0;
M[7] = 0;
M[8] = 0;
M[9] = 0;
//M[10]
M[11] = 1;
M[12] = 0;
M[13] = 0;
//M[14] = (T)(zNear*zFar/(zNear-zFar));
M[15] = 0;
if ( zClipFromZero ) // DirectX version
{
M[10] = (T)(zFar/(zFar-zNear));
M[14] = (T)(zNear*zFar/(zNear-zFar));
}
else // OpenGL version
{
M[10] = (T)((zFar+zNear)/(zFar-zNear));
M[14] = (T)(2.0f*zNear*zFar/(zNear-zFar));
}
#if defined ( USE_MATRIX_TEST )
definitelyIdentityMatrix=false;
#endif
return *this;
return buildProjectionMatrixPerspectiveFov(sx, sy, zNear, zFar, zClipFromZero, (T)1);
}
@ -2399,4 +2313,3 @@ namespace core
} // end namespace irr
#endif

View File

@ -235,7 +235,10 @@ namespace core
}
//! Rotates the vector by a specified number of degrees around the Y axis and the specified center.
/** \param degrees Number of degrees to rotate around the Y axis.
/** CAREFUL: For historical reasons rotateXZBy uses a right-handed rotation
(maybe to make it more similar to the 2D vector rotations which are counterclockwise).
To have this work the same way as rest of Irrlicht (nodes, matrices, other rotateBy functions) pass -1*degrees in here.
\param degrees Number of degrees to rotate around the Y axis.
\param center The center of the rotation. */
void rotateXZBy(f64 degrees, const vector3d<T>& center=vector3d<T>())
{

View File

@ -8,7 +8,7 @@
#include "C3DSMeshFileLoader.h"
#include "CMeshTextureLoader.h"
#include "os.h"
#include "SMeshBuffer.h"
#include "CMeshBuffer.h"
#include "SAnimatedMesh.h"
#include "IReadFile.h"
#include "IVideoDriver.h"

View File

@ -10,7 +10,7 @@
#include "CColorConverter.h"
#include "CImage.h"
#include "coreutil.h"
#include "SMeshBuffer.h"
#include "CMeshBuffer.h"
#include "IVideoDriver.h"
#include "IFileSystem.h"

View File

@ -6,7 +6,6 @@
#ifdef _IRR_COMPILE_WITH_MD2_LOADER_
#include "CAnimatedMeshMD2.h"
#include "SColor.h"
#include "irrMath.h"
namespace irr

View File

@ -8,8 +8,6 @@
#include "IAnimatedMeshMD2.h"
#include "IMesh.h"
#include "CMeshBuffer.h"
#include "IReadFile.h"
#include "S3DVertex.h"
#include "irrArray.h"
#include "irrString.h"

View File

@ -8,11 +8,8 @@
#include "IAnimatedMeshMD3.h"
#include "IReadFile.h"
#include "IFileSystem.h"
#include "irrArray.h"
#include "irrString.h"
#include "SMesh.h"
#include "SMeshBuffer.h"
#include "IQ3Shader.h"
#include "CMeshBuffer.h"
namespace irr
{

View File

@ -5,8 +5,8 @@
#include "CAnimatedMeshSceneNode.h"
#include "IVideoDriver.h"
#include "ISceneManager.h"
#include "S3DVertex.h"
#include "os.h"
#include "IFileSystem.h"
#ifdef _IRR_COMPILE_WITH_SHADOW_VOLUME_SCENENODE_
#include "CShadowVolumeSceneNode.h"
#else
@ -14,9 +14,7 @@
#endif // _IRR_COMPILE_WITH_SHADOW_VOLUME_SCENENODE_
#include "IAnimatedMeshMD3.h"
#include "CSkinnedMesh.h"
#include "IDummyTransformationSceneNode.h"
#include "IBoneSceneNode.h"
#include "IMaterialRenderer.h"
#include "IMesh.h"
#include "IMeshCache.h"
#include "IAnimatedMesh.h"

View File

@ -2,7 +2,6 @@
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "CAttributes.h"
#include "fast_atof.h"
#include "ITexture.h"
#include "IVideoDriver.h"

View File

@ -13,7 +13,7 @@
#include "CMeshTextureLoader.h"
#include "IVideoDriver.h"
#include "IFileSystem.h"
#include "IAttributes.h"
#include "os.h"
#ifdef _DEBUG
@ -255,7 +255,7 @@ bool CB3DMeshFileLoader::readChunkMESH(CSkinnedMesh::SJoint *inJoint)
os::Printer::log(logStr.c_str(), ELL_DEBUG);
#endif
s32 brushID;
s32 brushID=-1;
B3DFile->read(&brushID, sizeof(brushID));
#ifdef __BIG_ENDIAN__
brushID = os::Byteswap::byteswap(brushID);
@ -283,11 +283,15 @@ bool CB3DMeshFileLoader::readChunkMESH(CSkinnedMesh::SJoint *inJoint)
{
scene::SSkinMeshBuffer *meshBuffer = AnimatedMesh->addMeshBuffer();
if (brushID!=-1)
if ( brushID >= 0 && (u32)brushID < Materials.size() )
{
loadTextures(Materials[brushID]);
meshBuffer->Material=Materials[brushID].Material;
}
else if (brushID != -1) // -1 is OK
{
os::Printer::log("Illegal brush ID found", B3DFile->getFileName(), ELL_WARNING);
}
if(readChunkTRIS(meshBuffer,AnimatedMesh->getMeshBuffers().size()-1, VerticesStart)==false)
return false;
@ -364,7 +368,8 @@ bool CB3DMeshFileLoader::readChunkVRTS(CSkinnedMesh::SJoint *inJoint)
tex_coord_set_size = os::Byteswap::byteswap(tex_coord_set_size);
#endif
if (tex_coord_sets >= max_tex_coords || tex_coord_set_size >= 4) // Something is wrong
if (tex_coord_sets < 0 || tex_coord_set_size < 0 ||
tex_coord_sets >= max_tex_coords || tex_coord_set_size >= 4) // Something is wrong
{
os::Printer::log("tex_coord_sets or tex_coord_set_size too big", B3DFile->getFileName(), ELL_ERROR);
return false;
@ -460,7 +465,7 @@ bool CB3DMeshFileLoader::readChunkTRIS(scene::SSkinMeshBuffer *meshBuffer, u32 m
bool showVertexWarning=false;
s32 triangle_brush_id; // Note: Irrlicht can't have different brushes for each triangle (using a workaround)
s32 triangle_brush_id=-1; // Note: Irrlicht can't have different brushes for each triangle (using a workaround)
B3DFile->read(&triangle_brush_id, sizeof(triangle_brush_id));
#ifdef __BIG_ENDIAN__
triangle_brush_id = os::Byteswap::byteswap(triangle_brush_id);
@ -468,14 +473,20 @@ bool CB3DMeshFileLoader::readChunkTRIS(scene::SSkinMeshBuffer *meshBuffer, u32 m
SB3dMaterial *B3dMaterial;
if (triangle_brush_id != -1)
if (triangle_brush_id >= 0 && (u32)triangle_brush_id < Materials.size())
{
loadTextures(Materials[triangle_brush_id]);
B3dMaterial = &Materials[triangle_brush_id];
meshBuffer->Material = B3dMaterial->Material;
}
else
{
B3dMaterial = 0;
if (triangle_brush_id < -1) // -1 is OK
{
os::Printer::log("Illegal material index for triangle brush found", B3DFile->getFileName(), ELL_WARNING);
}
}
const s32 memoryNeeded = B3dStack.getLast().length / sizeof(s32);
meshBuffer->Indices.reallocate(memoryNeeded + meshBuffer->Indices.size() + 1);
@ -594,7 +605,11 @@ bool CB3DMeshFileLoader::readChunkBONE(CSkinnedMesh::SJoint *inJoint)
#endif
globalVertexID += VerticesStart;
if (AnimatedVertices_VertexID[globalVertexID]==-1)
if (globalVertexID >= AnimatedVertices_VertexID.size())
{
os::Printer::log("Illegal vertex index found", B3DFile->getFileName(), ELL_WARNING);
}
else if (AnimatedVertices_VertexID[globalVertexID]==-1)
{
os::Printer::log("B3dMeshLoader: Weight has bad vertex id (no link to meshbuffer index found)");
}
@ -1081,10 +1096,9 @@ void CB3DMeshFileLoader::loadTextures(SB3dMaterial& material) const
void CB3DMeshFileLoader::readString(core::stringc& newstring)
{
newstring="";
while (B3DFile->getPos() <= B3DFile->getSize())
c8 character=0;
while (B3DFile->read(&character, sizeof(character)) > 0) // until eof
{
c8 character;
B3DFile->read(&character, sizeof(character));
if (character==0)
return;
newstring.append(character);

View File

@ -2,13 +2,12 @@
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
// TODO: replace printf's by logging messages
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_B3D_WRITER_
#include "CB3DMeshWriter.h"
#include "SB3DStructs.h"
#include "os.h"
#include "ISkinnedMesh.h"
#include "IMeshBuffer.h"

View File

@ -9,11 +9,8 @@
#include "IMeshWriter.h"
#include "IWriteFile.h"
#include "SB3DStructs.h"
#include "ISkinnedMesh.h"
namespace irr
{
namespace scene

View File

@ -7,7 +7,6 @@
#include "IMeshLoader.h"
#include "IFileSystem.h"
#include "IVideoDriver.h"
#include "ISceneManager.h"
#include "IQ3Shader.h"

View File

@ -8,7 +8,6 @@
#include "IVideoDriver.h"
#include "ISceneManager.h"
#include "ICameraSceneNode.h"
#include "os.h"
namespace irr
{

View File

@ -6,7 +6,7 @@
#define IRR_C_BILLBOARD_SCENE_NODE_H_INCLUDED
#include "IBillboardSceneNode.h"
#include "SMeshBuffer.h"
#include "CMeshBuffer.h"
namespace irr
{

View File

@ -18,7 +18,7 @@
#include "SMesh.h"
#include "IVideoDriver.h"
#include "SAnimatedMesh.h"
#include "SMeshBufferLightMap.h"
#include "CMeshBuffer.h"
#ifdef _DEBUG
#define _IRR_DEBUG_CSM_LOADER_

View File

@ -38,9 +38,7 @@
#ifndef __CSM_LOADER_H_INCLUDED__
#define __CSM_LOADER_H_INCLUDED__
#include "irrArray.h"
#include "IMesh.h"
#include "irrString.h"
#include "IFileSystem.h"
#include "IMeshLoader.h"

View File

@ -7,6 +7,7 @@
#include "CColladaFileLoader.h"
#include "CMeshTextureLoader.h"
#include "CAttributes.h"
#include "os.h"
#include "IXMLReader.h"
#include "IDummyTransformationSceneNode.h"
@ -21,6 +22,7 @@
#include "IMeshCache.h"
#include "IMeshSceneNode.h"
#include "CDynamicMeshBuffer.h"
#include "IVideoDriver.h"
#include "irrMap.h"
#ifdef _DEBUG

View File

@ -7,12 +7,11 @@
#include "IMeshLoader.h"
#include "IFileSystem.h"
#include "IVideoDriver.h"
#include "irrString.h"
#include "SMesh.h"
#include "ISceneManager.h"
#include "irrMap.h"
#include "CAttributes.h"
#include "IAttributes.h"
namespace irr
{

View File

@ -14,7 +14,6 @@
#include "IWriteFile.h"
#include "IXMLWriter.h"
#include "IMesh.h"
#include "IAttributes.h"
#include "IAnimatedMeshSceneNode.h"
#include "IMeshSceneNode.h"
#include "ITerrainSceneNode.h"

View File

@ -3,9 +3,8 @@
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "CColorConverter.h"
#include "SColor.h"
#include "IImage.h"
#include "os.h"
#include "irrString.h"
namespace irr
{

View File

@ -6,7 +6,7 @@
#define IRR_C_COLOR_CONVERTER_H_INCLUDED
#include "irrTypes.h"
#include "IImage.h"
#include "SColor.h"
namespace irr
{

View File

@ -7,9 +7,6 @@
#include "CCubeSceneNode.h"
#include "IVideoDriver.h"
#include "ISceneManager.h"
#include "S3DVertex.h"
#include "SMeshBuffer.h"
#include "os.h"
#ifdef _IRR_COMPILE_WITH_SHADOW_VOLUME_SCENENODE_
#include "CShadowVolumeSceneNode.h"
#else

View File

@ -6,7 +6,7 @@
#define IRR_C_CUBE_SCENE_NODE_H_INCLUDED
#include "IMeshSceneNode.h"
#include "SMesh.h"
#include "IMesh.h"
#include "IGeometryCreator.h"
namespace irr

View File

@ -25,10 +25,11 @@
#include "CMeshTextureLoader.h"
#include "ISceneManager.h"
#include "IAttributes.h"
#include "IVideoDriver.h"
#include "SAnimatedMesh.h"
#include "SSkinMeshBuffer.h"
#include "SMesh.h"
#include "irrString.h"
#include "irrMath.h"
#include "dmfsupport.h"
namespace irr

View File

@ -33,10 +33,7 @@
#include "IMeshLoader.h"
#include "IReadFile.h"
#include "IFileSystem.h"
#include "SMesh.h"
#include "IVideoDriver.h"
#include "ISceneManager.h"
#include "SAnimatedMesh.h"
namespace irr
{

View File

@ -3,11 +3,10 @@
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "CFileList.h"
#include "IrrCompileConfig.h"
#include "irrArray.h"
#include "coreutil.h"
#include "os.h"
#include "os.h" // debug logging
namespace irr
{

View File

@ -12,10 +12,6 @@
#include "IGUIButton.h"
#include "IGUIStaticText.h"
#include "IGUIFont.h"
#include "IGUISpriteBank.h"
#include "IFileList.h"
#include "os.h"
#include "fast_atof.h"
namespace irr
{

View File

@ -6,13 +6,11 @@
#ifdef _IRR_COMPILE_WITH_GUI_
#include "IGUIEnvironment.h"
#include "IVideoDriver.h"
#include "IGUISkin.h"
#include "IGUIEnvironment.h"
#include "IGUIFont.h"
#include "IGUIButton.h"
#include "CGUIListBox.h"
#include "os.h"
namespace irr
{

View File

@ -8,7 +8,6 @@
#include "IGUISkin.h"
#include "IGUIEnvironment.h"
#include "IVideoDriver.h"
#include "IGUIFont.h"
#include "IGUISpriteBank.h"
#include "os.h"

View File

@ -8,7 +8,6 @@
#include "IGUISkin.h"
#include "IGUIEnvironment.h"
#include "IGUIFont.h"
#include "IVideoDriver.h"
#include "rect.h"
#include "os.h"
#include "Keycodes.h"

View File

@ -9,13 +9,9 @@
#include "IGUISkin.h"
#include "IGUIEnvironment.h"
#include "IVideoDriver.h"
#include "IGUIButton.h"
#include "IGUIStaticText.h"
#include "IGUIFont.h"
#include "IGUIFontBitmap.h"
#include "IFileList.h"
#include "os.h"
namespace irr
{

View File

@ -8,7 +8,6 @@
#include "CGUIListBox.h"
#include "IGUISkin.h"
#include "IGUIEnvironment.h"
#include "IVideoDriver.h"
#include "IGUIFont.h"
#include "IGUISpriteBank.h"
#include "CGUIScrollBar.h"

View File

@ -7,12 +7,9 @@
#include "IGUISkin.h"
#include "IGUIEnvironment.h"
#include "IVideoDriver.h"
#include "IGUIFont.h"
#include "IGUIWindow.h"
#include "os.h"
namespace irr
{
namespace gui

View File

@ -8,7 +8,6 @@
#include "IGUISkin.h"
#include "IGUIEnvironment.h"
#include "IGUIButton.h"
#include "IGUIFont.h"
#include "ITexture.h"
namespace irr

View File

@ -11,7 +11,6 @@
#include "CGUIWindow.h"
#include "IGUIStaticText.h"
#include "IGUIImage.h"
#include "irrArray.h"
namespace irr
{

View File

@ -7,7 +7,6 @@
#include "IGUIEnvironment.h"
#include "os.h"
#include "IVideoDriver.h"
#include "IGUISkin.h"
namespace irr

View File

@ -8,7 +8,7 @@
#include "IGUITable.h"
#include "IGUIScrollBar.h"
#include "IGUIEnvironment.h"
#include "CProfiler.h"
#include "IProfiler.h"
namespace irr
{

View File

@ -7,11 +7,7 @@
#include "IGUISkin.h"
#include "IGUIEnvironment.h"
#include "IVideoDriver.h"
#include "CGUIButton.h"
#include "IGUIFont.h"
#include "IGUIFontBitmap.h"
#include "os.h"
namespace irr
{

View File

@ -4,12 +4,11 @@
#include "CGUISpinBox.h"
#ifdef _IRR_COMPILE_WITH_GUI_
#include "CGUIEditBox.h"
#include "CGUIButton.h"
#include "IGUIEditBox.h"
#include "IGUIButton.h"
#include "IGUIEnvironment.h"
#include "IEventReceiver.h"
#include "fast_atof.h"
#include <wchar.h>
namespace irr
@ -131,7 +130,7 @@ void CGUISpinBox::setRange(f32 min, f32 max)
RangeMin = min;
RangeMax = max;
// we have to round the range - otherwise we can get into an infinte setValue/verifyValueRange cycle.
// we have to round the range - otherwise we can get into an infinite setValue/verifyValueRange cycle.
wchar_t str[100];
swprintf_irr(str, 99, FormatString.c_str(), RangeMin);
RangeMin = core::fast_atof(core::stringc(str).c_str());

View File

@ -5,13 +5,12 @@
#include "CGUITabControl.h"
#ifdef _IRR_COMPILE_WITH_GUI_
#include "CGUIButton.h"
#include "IGUIButton.h"
#include "IGUISkin.h"
#include "IGUIEnvironment.h"
#include "IGUIFont.h"
#include "IVideoDriver.h"
#include "rect.h"
#include "os.h"
namespace irr
{

View File

@ -10,7 +10,6 @@
#include "IGUITabControl.h"
#include "irrArray.h"
#include "IGUISkin.h"
namespace irr
{

View File

@ -12,8 +12,7 @@
#include "IGUIEnvironment.h"
#include "IVideoDriver.h"
#include "IGUIFont.h"
#include "CGUIScrollBar.h"
#include "os.h"
#include "IGUIScrollBar.h"
#define ARROW_PAD 15

View File

@ -7,7 +7,6 @@
#include "IGUISkin.h"
#include "IGUIEnvironment.h"
#include "IVideoDriver.h"
#include "IGUIButton.h"
#include "IGUIFont.h"
#include "CGUIButton.h"

View File

@ -13,7 +13,6 @@
#include "IVideoDriver.h"
#include "IGUIFont.h"
#include "CGUIScrollBar.h"
#include "os.h"
namespace irr
{

View File

@ -7,10 +7,8 @@
#include "IGUISkin.h"
#include "IGUIEnvironment.h"
#include "IVideoDriver.h"
#include "IGUIButton.h"
#include "IGUIFont.h"
#include "IGUIFontBitmap.h"
namespace irr
{

View File

@ -3,8 +3,6 @@
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "CGeometryCreator.h"
#include "SAnimatedMesh.h"
#include "SMeshBuffer.h"
#include "SMesh.h"
#include "IMesh.h"
#include "IVideoDriver.h"

View File

@ -6,7 +6,7 @@
#define IRR_C_GEOMETRY_CREATOR_H_INCLUDED
#include "IGeometryCreator.h"
#include "SMeshBuffer.h"
#include "CMeshBuffer.h"
namespace irr
{

View File

@ -3,7 +3,6 @@
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "CImage.h"
#include "irrString.h"
#include "CColorConverter.h"
#include "CBlit.h"
#include "os.h"

View File

@ -11,7 +11,6 @@
#include "CColorConverter.h"
#include "CImage.h"
#include "os.h"
#include "irrString.h"
namespace irr
{
@ -48,19 +47,35 @@ bool CImageLoaderBMP::isALoadableFileFormat(io::IReadFile* file) const
}
// UB-safe overflow check
static inline bool doesOverflow(const void *base, size_t numElements, const void *end)
{
// TODO: uintptr_t (as in original patch from sfan5) would be nicer than size_t, use once we allow c++11
size_t baseI = reinterpret_cast<size_t>(base);
size_t endI = reinterpret_cast<size_t>(end);
return baseI > endI || numElements >= (endI - baseI);
}
// check whether &p[0] to &p[_off - 1] can be accessed
#define EXIT_P_OVERFLOW(_off) if (doesOverflow(p, _off, pEnd)) goto exit
// same for d
#define EXIT_D_OVERFLOW(_off) if (doesOverflow(d, _off, destEnd)) goto exit
void CImageLoaderBMP::decompress8BitRLE(u8*& bmpData, s32 size, s32 width, s32 height, s32 pitch) const
{
u8* p = bmpData;
const u8* pEnd = bmpData + size;
u8* newBmp = new u8[(width+pitch)*height];
u8* d = newBmp;
u8* destEnd = newBmp + (width+pitch)*height;
const u8* destEnd = newBmp + (width+pitch)*height;
s32 line = 0;
while (bmpData - p < size && d < destEnd)
while (p < pEnd && d < destEnd)
{
if (*p == 0)
{
++p;
EXIT_P_OVERFLOW(1);
switch(*p)
{
@ -70,37 +85,43 @@ void CImageLoaderBMP::decompress8BitRLE(u8*& bmpData, s32 size, s32 width, s32 h
d = newBmp + (line*(width+pitch));
break;
case 1: // end of bmp
delete [] bmpData;
bmpData = newBmp;
return;
goto exit;
case 2:
++p; d +=(u8)*p; // delta
++p; d += ((u8)*p)*(width+pitch);
++p;
EXIT_P_OVERFLOW(2);
d += (u8)*p; // delta
++p;
d += ((u8)*p)*(width+pitch);
++p;
break;
default:
{
// absolute mode
s32 count = (u8)*p; ++p;
s32 readAdditional = ((2-(count%2))%2);
s32 i;
const s32 count = (u8)*p;
++p;
for (i=0; i<count; ++i)
EXIT_P_OVERFLOW(count);
EXIT_D_OVERFLOW(count);
for (s32 i=0; i<count; ++i)
{
*d = *p;
++p;
++d;
}
for (i=0; i<readAdditional; ++i)
const s32 readAdditional = ((2-(count%2))%2);
EXIT_P_OVERFLOW(readAdditional);
for (s32 i=0; i<readAdditional; ++i)
++p;
}
}
}
else
{
s32 count = (u8)*p; ++p;
const s32 count = (u8)*p; ++p;
EXIT_P_OVERFLOW(1);
u8 color = *p; ++p;
EXIT_D_OVERFLOW(count);
for (s32 i=0; i<count; ++i)
{
*d = color;
@ -109,63 +130,97 @@ void CImageLoaderBMP::decompress8BitRLE(u8*& bmpData, s32 size, s32 width, s32 h
}
}
exit:
delete [] bmpData;
bmpData = newBmp;
}
// how many new bytes will be touched given the current state of decompress4BitRLE
static inline u32 shiftedCount(s32 count, s32 shift)
{
IRR_DEBUG_BREAK_IF(count <= 0)
u32 ret = 0;
if ( shift == 0 ) // using up half of an old byte
{
--count;
}
ret += (count / 2) + (count % 2);
return ret;
}
// Ensure current row/line are inside width/height
// Didn't find any documentation how BMP's are supposed to handle this
// I think in general "good" bmp's are supposed to not go over line-ends
#define KEEP_ROW_LINE_INSIDE \
if ( row >= width ) \
{ \
line += row/width; \
row %= width; \
} \
if ( line >= height ) \
{ \
line = 0; /* bug anyway, this way more visible maybe */ \
}
void CImageLoaderBMP::decompress4BitRLE(u8*& bmpData, s32 size, s32 width, s32 height, s32 pitch) const
{
s32 lineWidth = (width+1)/2+pitch;
const s32 lineWidth = (width+1)/2+pitch;
u8* p = bmpData;
const u8* pEnd = bmpData + size;
u8* newBmp = new u8[lineWidth*height];
u8* d = newBmp;
u8* destEnd = newBmp + lineWidth*height;
memset(newBmp, 0, lineWidth*height); // Extra cost, but otherwise we have to code pixel skipping stuff
const u8* destEnd = newBmp + lineWidth*height;
s32 line = 0;
s32 shift = 4;
s32 row = 0;
while (bmpData - p < size && d < destEnd)
while (p < pEnd)
{
if (*p == 0)
{
++p;
EXIT_P_OVERFLOW(1);
switch(*p)
{
case 0: // end of line
++p;
++line;
d = newBmp + (line*lineWidth);
shift = 4;
row = 0;
break;
case 1: // end of bmp
delete [] bmpData;
bmpData = newBmp;
return;
case 2:
goto exit;
case 2: // delta
{
++p;
EXIT_P_OVERFLOW(2);
s32 x = (u8)*p; ++p;
s32 y = (u8)*p; ++p;
d += x/2 + y*lineWidth;
shift = x%2==0 ? 4 : 0;
row += x;
line += y;
}
break;
default:
{
// absolute mode
s32 count = (u8)*p; ++p;
s32 readAdditional = ((2-((count)%2))%2);
const u32 count = (u8)*p; ++p;
s32 readShift = 4;
s32 i;
for (i=0; i<count; ++i)
KEEP_ROW_LINE_INSIDE;
s32 shift = row%2 == 0 ? 4 : 0;
u8* d = newBmp + (lineWidth*line + row/2);
EXIT_P_OVERFLOW(shiftedCount(count, readShift));
EXIT_D_OVERFLOW(shiftedCount(count, shift));
for (u32 i=0; i<count; ++i)
{
s32 color = (((u8)*p) >> readShift) & 0x0f;
readShift -= 4;
if (readShift < 0)
{
++*p;
++p;
readShift = 4;
}
@ -178,26 +233,37 @@ void CImageLoaderBMP::decompress4BitRLE(u8*& bmpData, s32 size, s32 width, s32 h
shift = 4;
++d;
}
}
row += count;
for (i=0; i<readAdditional; ++i)
// pixels always come in 2-byte packages with unused half-bytes filled with zeroes
const u32 modCount = (count%4);
const u32 readAdditional = modCount == 1 ? 2 : (modCount==0?0:1); // jump 2,1,1,0 for count 1,2,3,4
EXIT_P_OVERFLOW(readAdditional);
for (u32 i=0; i<readAdditional; ++i)
++p;
}
}
}
else
else // encoded mode
{
s32 count = (u8)*p; ++p;
s32 color1 = (u8)*p; color1 = color1 & 0x0f;
s32 color2 = (u8)*p; color2 = (color2 >> 4) & 0x0f;
const s32 count = (u8)*p; // pixels to draw
++p;
EXIT_P_OVERFLOW(1);
s32 color1 = (u8)*p; color1 = color1 & 0x0f; // lo bit (2nd,4th,... pixel)
s32 color2 = (u8)*p; color2 = (color2 >> 4) & 0x0f; // hi bits (1st,3rd,... pixel)
++p;
KEEP_ROW_LINE_INSIDE;
s32 shift = row%2 == 0 ? 4 : 0;
u8* d = newBmp + (lineWidth*line + row/2);
EXIT_D_OVERFLOW(shiftedCount(count, shift));
for (s32 i=0; i<count; ++i)
{
u8 mask = 0x0f << shift;
u8 toSet = (shift==0 ? color1 : color2) << shift;
*d = (*d & (~mask)) | (toSet & mask);
u8 toSet = ((i%2==0) ? color2 : color1) << shift;
*d = (*d & (~mask)) | toSet;
shift -= 4;
if (shift < 0)
@ -206,14 +272,18 @@ void CImageLoaderBMP::decompress4BitRLE(u8*& bmpData, s32 size, s32 width, s32 h
++d;
}
}
row += count;
}
}
exit:
delete [] bmpData;
bmpData = newBmp;
}
#undef EXIT_P_OVERFLOW
#undef EXIT_D_OVERFLOW
#undef KEEP_ROW_LINE_INSIDE
//! creates a surface from the file
IImage* CImageLoaderBMP::loadImage(io::IReadFile* file) const
@ -239,12 +309,25 @@ IImage* CImageLoaderBMP::loadImage(io::IReadFile* file) const
header.ImportantColors = os::Byteswap::byteswap(header.ImportantColors);
#endif
s32 pitch = 0;
//! return if the header is false
if (header.Id != 0x4d42)
bool topDown = false;
if (header.Id == 0x4d42) // BM = Windows header
{
// Sizes are signed integer with Windows header (unsigned with OS/2)
// Not sure if negative Width has any meaning, but negative height is for upside-down
header.Width = core::abs_((s32)header.Width);
if ( (s32)header.Height < 0 )
{
topDown = true;
header.Height = core::abs_((s32)header.Height);
}
}
else
{
os::Printer::log("BMP files with OS/2 Headers not supported.", ELL_ERROR);
return 0;
}
if (header.Compression > 2) // we'll only handle RLE-Compression
{
@ -282,14 +365,9 @@ IImage* CImageLoaderBMP::loadImage(io::IReadFile* file) const
file->seek(header.BitmapDataOffset);
f32 t = (header.Width) * (header.BPP / 8.0f);
s32 widthInBytes = (s32)t;
t -= widthInBytes;
if (t!=0.0f)
++widthInBytes;
s32 lineData = widthInBytes + ((4-(widthInBytes%4)))%4;
pitch = lineData - widthInBytes;
const s32 widthInBytes = core::ceil32(header.Width * (header.BPP / 8.0f));
const s32 lineSize = widthInBytes + ((4-(widthInBytes%4)))%4;
const s32 pitch = lineSize - widthInBytes;
u8* bmpData = new u8[header.BitmapDataSize];
file->read(bmpData, header.BitmapDataSize);
@ -297,14 +375,25 @@ IImage* CImageLoaderBMP::loadImage(io::IReadFile* file) const
// decompress data if needed
switch(header.Compression)
{
case 1: // 8 bit rle
case 1: // 8 bit RLE
decompress8BitRLE(bmpData, header.BitmapDataSize, header.Width, header.Height, pitch);
header.BitmapDataSize = (header.Width + pitch) * header.Height;
break;
case 2: // 4 bit rle
case 2: // 4 bit RLE
decompress4BitRLE(bmpData, header.BitmapDataSize, header.Width, header.Height, pitch);
header.BitmapDataSize = ((header.Width+1)/2 + pitch) * header.Height;
break;
}
if (header.BitmapDataSize < lineSize * header.Height)
{
os::Printer::log("Bitmap data is cut off.", ELL_ERROR);
delete [] paletteData;
delete [] bmpData;
return 0;
}
// create surface
// no default constructor from packed area! ARM problem!
@ -359,6 +448,9 @@ cleanup:
delete [] paletteData;
delete [] bmpData;
if ( image && topDown )
image->flip(true, false);
return image;
}

View File

@ -18,9 +18,7 @@
#include "IReadFile.h"
#include "os.h"
#include "CColorConverter.h"
#include "CImage.h"
#include "irrString.h"
// Header flag values
#define DDSD_CAPS 0x00000001
@ -721,9 +719,8 @@ IImage* CImageLoaderDDS::loadImage(io::IReadFile* file) const
image = new CImage(ECF_A8R8G8B8, core::dimension2d<u32>(width, height));
if (DDSDecompress(&header, memFile, (u8*)image->lock()) == -1)
if (DDSDecompress(&header, memFile, (u8*)image->getData()) == -1)
{
image->unlock();
image->drop();
image = 0;
}

View File

@ -11,7 +11,6 @@
#include "CColorConverter.h"
#include "CImage.h"
#include "os.h"
#include "irrString.h"
namespace irr

View File

@ -15,7 +15,7 @@
#endif // _IRR_COMPILE_WITH_LIBPNG_
#include "CImage.h"
#include "CReadFile.h"
#include "IReadFile.h"
#include "os.h"
namespace irr

View File

@ -9,7 +9,6 @@
#include "IReadFile.h"
#include "os.h"
#include "CImage.h"
#include "irrString.h"
namespace irr

View File

@ -9,7 +9,6 @@
#include "IReadFile.h"
#include "os.h"
#include "CImage.h"
#include "irrString.h"
namespace irr
{

View File

@ -130,7 +130,6 @@ DUMMY - This 404 bytes of data should be set to 0. This makes the Header exactl
#include "CColorConverter.h"
#include "CImage.h"
#include "os.h"
#include "irrString.h"
namespace irr

View File

@ -10,7 +10,6 @@
#include "os.h"
#include "CColorConverter.h"
#include "CImage.h"
#include "irrString.h"
namespace irr
@ -33,10 +32,10 @@ u8 *CImageLoaderTGA::loadCompressedImage(io::IReadFile *file, const STGAHeader&
// This was written and sent in by Jon Pry, thank you very much!
// I only changed the formatting a little bit.
s32 bytesPerPixel = header.PixelDepth/8;
s32 imageSize = header.ImageHeight * header.ImageWidth * bytesPerPixel;
const u32 bytesPerPixel = header.PixelDepth/8;
const u32 imageSize = header.ImageHeight * header.ImageWidth * bytesPerPixel;
u8* data = new u8[imageSize];
s32 currentByte = 0;
u32 currentByte = 0;
while(currentByte < imageSize)
{
@ -47,8 +46,17 @@ u8 *CImageLoaderTGA::loadCompressedImage(io::IReadFile *file, const STGAHeader&
{
chunkheader++; // Add 1 To The Value To Get Total Number Of Raw Pixels
file->read(&data[currentByte], bytesPerPixel * chunkheader);
currentByte += bytesPerPixel * chunkheader;
const u32 bytesToRead = bytesPerPixel * chunkheader;
if ( currentByte+bytesToRead < imageSize )
{
file->read(&data[currentByte], bytesToRead);
currentByte += bytesToRead;
}
else
{
os::Printer::log("Compressed TGA file RAW chunk tries writing beyond buffer", file->getFileName(), ELL_WARNING);
break;
}
}
else
{
@ -57,15 +65,27 @@ u8 *CImageLoaderTGA::loadCompressedImage(io::IReadFile *file, const STGAHeader&
// If It's An RLE Header
chunkheader -= 127; // Subtract 127 To Get Rid Of The ID Bit
s32 dataOffset = currentByte;
file->read(&data[dataOffset], bytesPerPixel);
currentByte += bytesPerPixel;
for(s32 counter = 1; counter < chunkheader; counter++)
u32 dataOffset = currentByte;
if ( dataOffset+bytesPerPixel < imageSize )
{
for(s32 elementCounter=0; elementCounter < bytesPerPixel; elementCounter++)
data[currentByte + elementCounter] = data[dataOffset + elementCounter];
file->read(&data[dataOffset], bytesPerPixel);
currentByte += bytesPerPixel;
}
else
{
os::Printer::log("Compressed TGA file RLE headertries writing beyond buffer", file->getFileName(), ELL_WARNING);
break;
}
for(u32 counter = 1; counter < chunkheader; counter++)
{
if ( currentByte + bytesPerPixel <= imageSize )
{
for(u32 elementCounter=0; elementCounter < bytesPerPixel; elementCounter++)
{
data[currentByte + elementCounter] = data[dataOffset + elementCounter];
}
}
currentByte += bytesPerPixel;
}
@ -118,8 +138,17 @@ IImage* CImageLoaderTGA::loadImage(io::IReadFile* file) const
if (header.ColorMapType)
{
// create 32 bit palette
palette = new u32[ header.ColorMapLength];
// Create 32 bit palette
const irr::u16 paletteSize = core::max_((u16)256, header.ColorMapLength); // ColorMapLength can lie, but so far we only use palette for 8-bit, so ensure it has 256 entries
palette = new u32[paletteSize];
if( paletteSize > header.ColorMapLength )
{
// To catch images using palette colors with invalid indices
const irr::u32 errorCol = irr::video::SColor(255,255, 0, 205).color; // bright magenta
for ( irr::u16 i = header.ColorMapLength; i< paletteSize; ++i )
palette[i] = errorCol;
}
// read color map
u8 * colorMap = new u8[header.ColorMapEntrySize/8 * header.ColorMapLength];
@ -150,7 +179,7 @@ IImage* CImageLoaderTGA::loadImage(io::IReadFile* file) const
header.ImageType == 3 // Uncompressed, black and white images
)
{
const s32 imageSize = header.ImageHeight * header.ImageWidth * header.PixelDepth/8;
const s32 imageSize = header.ImageHeight * header.ImageWidth * (header.PixelDepth/8);
data = new u8[imageSize];
file->read(data, imageSize);
}
@ -185,14 +214,28 @@ IImage* CImageLoaderTGA::loadImage(io::IReadFile* file) const
}
else
{
image = new CImage(ECF_A1R5G5B5,
core::dimension2d<u32>(header.ImageWidth, header.ImageHeight));
if (image)
CColorConverter::convert8BitTo16Bit((u8*)data,
(s16*)image->getData(),
header.ImageWidth,header.ImageHeight,
(s32*) palette, 0,
(header.ImageDescriptor&0x20)==0);
switch ( header.ColorMapEntrySize )
{
case 16:
image = new CImage(ECF_A1R5G5B5, core::dimension2d<u32>(header.ImageWidth, header.ImageHeight));
if ( image )
CColorConverter::convert8BitTo16Bit((u8*)data,
(s16*)image->getData(),
header.ImageWidth,header.ImageHeight,
(s32*) palette, 0,
(header.ImageDescriptor&0x20)==0);
break;
// Note: 24 bit with palette would need a 24 bit palette, too lazy doing that now (textures will prefer 32-bit later anyway)
default:
image = new CImage(ECF_A8R8G8B8, core::dimension2d<u32>(header.ImageWidth, header.ImageHeight));
if ( image )
CColorConverter::convert8BitTo32Bit((u8*)data,
(u8*)image->getData(),
header.ImageWidth,header.ImageHeight,
(u8*) palette, 0,
(header.ImageDescriptor&0x20)==0);
break;
}
}
}
break;

View File

@ -9,8 +9,6 @@
#include "CImage.h"
#include "os.h"
#include "dimension2d.h"
#include "IVideoDriver.h"
#include "IFileSystem.h"
#include "IReadFile.h"
#include "irrString.h"

View File

@ -9,7 +9,6 @@
#include "CImageLoaderBMP.h"
#include "IWriteFile.h"
#include "CColorConverter.h"
#include "irrString.h"
#include "os.h"
namespace irr

View File

@ -8,8 +8,7 @@
#include "CColorConverter.h"
#include "IWriteFile.h"
#include "CImage.h"
#include "irrString.h"
#include "IImage.h"
#include "os.h"
#ifdef _IRR_COMPILE_WITH_LIBJPEG_

View File

@ -6,10 +6,9 @@
#ifdef _IRR_COMPILE_WITH_PCX_WRITER_
#include "CImageLoaderPCX.h"
#include "IWriteFile.h"
#include "IImage.h"
#include "os.h" // for logging
#include "irrString.h"
namespace irr
{

View File

@ -6,10 +6,9 @@
#ifdef _IRR_COMPILE_WITH_PNG_WRITER_
#include "CImageLoaderPNG.h"
#include "IImage.h"
#include "CColorConverter.h"
#include "IWriteFile.h"
#include "irrString.h"
#include "os.h" // for logging
#ifdef _IRR_COMPILE_WITH_LIBPNG_

View File

@ -9,7 +9,6 @@
#include "IWriteFile.h"
#include "IImage.h"
#include "dimension2d.h"
#include "irrString.h"
namespace irr
{

View File

@ -9,7 +9,6 @@
#include "CImageLoaderPSD.h"
#include "IWriteFile.h"
#include "os.h" // for logging
#include "irrString.h"
namespace irr
{

View File

@ -9,7 +9,6 @@
#include "CImageLoaderTGA.h"
#include "IWriteFile.h"
#include "CColorConverter.h"
#include "irrString.h"
#include "os.h"
namespace irr

View File

@ -26,7 +26,7 @@ namespace irr
class CIrrDeviceMacOSX;
}
@interface CIrrDelegateOSX : NSObject
@interface CIrrDelegateOSX : NSObject <NSApplicationDelegate, NSWindowDelegate>
- (id)initWithDevice:(irr::CIrrDeviceMacOSX*)device;
- (void)terminate:(id)sender;

View File

@ -579,7 +579,7 @@ CIrrDeviceMacOSX::CIrrDeviceMacOSX(const SIrrlichtCreationParameters& param)
{
[[NSAutoreleasePool alloc] init];
[[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
[NSApp setDelegate:(id<NSApplicationDelegate>)[[[CIrrDelegateOSX alloc] initWithDevice:this] autorelease]];
[[NSApplication sharedApplication] setDelegate:[[[CIrrDelegateOSX alloc] initWithDevice:this] autorelease]];
// Create menu
@ -794,7 +794,7 @@ bool CIrrDeviceMacOSX::createWindow()
{
if (Window)
{
[Window setDelegate:(id<NSWindowDelegate>)[NSApp delegate]];
[Window setDelegate:(CIrrDelegateOSX *)[NSApp delegate]];
[Window setAcceptsMouseMovedEvents:TRUE];
[Window setIsVisible:TRUE];
[Window makeKeyAndOrderFront:nil];
@ -867,7 +867,7 @@ void CIrrDeviceMacOSX::createDriver()
SoftwareRendererType = 2;
if (Window)
{
Window.contentView.wantsLayer = YES;
[[Window contentView] setWantsLayer:YES];
}
#else
os::Printer::log("No Software driver support compiled in.", ELL_ERROR);
@ -880,7 +880,7 @@ void CIrrDeviceMacOSX::createDriver()
SoftwareRendererType = 1;
if (Window)
{
Window.contentView.wantsLayer = YES;
[[Window contentView] setWantsLayer:YES];
[ Window setOpaque:YES];
}
@ -1602,7 +1602,7 @@ bool CIrrDeviceMacOSX::present(video::IImage* surface, void* windowId, core::rec
NSImage *image = [[[NSImage alloc] initWithSize: imageSize] autorelease];
[image addRepresentation: rep];
Window.contentView.layer.contents = image;
[[[Window contentView] layer] setContents:image];
}
return true;
}

View File

@ -9,8 +9,6 @@
#ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_
#include "CIrrDeviceStub.h"
#include "IrrlichtDevice.h"
#include "IImagePresenter.h"
#define WIN32_LEAN_AND_MEAN
#if !defined(_IRR_XBOX_PLATFORM_)
@ -71,7 +69,7 @@ namespace irr
virtual video::IVideoModeList* getVideoModeList() IRR_OVERRIDE;
//! Notifies the device, that it has been resized
/** Must be publis as it is called from free function (event handler) */
/** Must be public as it is called from free function (event handler) */
void OnResized();
//! Sets if the window should be resizable in windowed mode.

View File

@ -9,12 +9,12 @@
#include "os.h"
#include "IXMLReader.h"
#include "SAnimatedMesh.h"
#include "SMesh.h"
#include "fast_atof.h"
#include "IReadFile.h"
#include "IAttributes.h"
#include "IMeshSceneNode.h"
#include "IVideoDriver.h"
#include "CDynamicMeshBuffer.h"
#include "SMeshBufferLightMap.h"
namespace irr
{

View File

@ -7,10 +7,6 @@
#include "IMeshLoader.h"
#include "IFileSystem.h"
#include "IVideoDriver.h"
#include "irrString.h"
#include "SMesh.h"
#include "SMeshBuffer.h"
#include "CDynamicMeshBuffer.h"
#include "ISceneManager.h"

View File

@ -70,13 +70,12 @@ Version 1.0 - 29 July 2004
#include "CLMTSMeshFileLoader.h"
#include "CMeshTextureLoader.h"
#include "SMeshBufferLightMap.h"
#include "CMeshBuffer.h"
#include "SAnimatedMesh.h"
#include "SMeshBuffer.h"
#include "SceneParameters.h"
#include "irrString.h"
#include "IReadFile.h"
#include "IAttributes.h"
#include "ISceneManager.h"
#include "os.h"
namespace irr

View File

@ -6,7 +6,7 @@
#define IRR_C_LWO_MESH_FILE_LOADER_H_INCLUDED
#include "IMeshLoader.h"
#include "SMeshBuffer.h"
#include "CMeshBuffer.h"
#include "irrString.h"
namespace irr

View File

@ -3,7 +3,6 @@
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "CLimitReadFile.h"
#include "irrString.h"
namespace irr
{

View File

@ -6,7 +6,6 @@
#define IRR_C_LIMIT_READ_FILE_H_INCLUDED
#include "IReadFile.h"
#include "irrString.h"
namespace irr
{

View File

@ -3,6 +3,8 @@
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "CLogger.h"
#include "os.h"
#include "irrString.h"
namespace irr
{

View File

@ -6,8 +6,6 @@
#define IRR_C_LOGGER_H_INCLUDED
#include "ILogger.h"
#include "os.h"
#include "irrString.h"
#include "IEventReceiver.h"
namespace irr

View File

@ -7,6 +7,8 @@
#include "CMD2MeshFileLoader.h"
#include "CAnimatedMeshMD2.h"
#include "coreutil.h"
#include "IReadFile.h"
#include "os.h"
namespace irr

View File

@ -7,7 +7,7 @@
#include "CMD3MeshFileLoader.h"
#include "CAnimatedMeshMD3.h"
#include "irrString.h"
#include "IVideoDriver.h"
namespace irr
{

View File

@ -6,10 +6,7 @@
#define IRR_C_MD3_MESH_FILE_LOADER_H_INCLUDED
#include "IMeshLoader.h"
#include "IFileSystem.h"
#include "IVideoDriver.h"
#include "ISceneManager.h"
#include "IQ3Shader.h"
namespace irr
{

View File

@ -15,7 +15,7 @@
#include "CMeshTextureLoader.h"
#include "SAnimatedMesh.h"
#include "SMeshBuffer.h"
#include "SMesh.h"
#include "IReadFile.h"
#include "IAttributes.h"

View File

@ -29,8 +29,7 @@
#include "IMeshLoader.h"
#include "SMesh.h"
#include "SMeshBufferLightMap.h"
#include "CMeshBuffer.h"
#include "IFileSystem.h"
#include "IVideoDriver.h"
#include "irrString.h"

Some files were not shown because too many files have changed in this diff Show More