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) 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) - 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. - 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 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 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. - 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. Thanks @Ryan Schmidt for bug report and patch.
- Fix: The build-in libpng now uses same zlib headers as rest of Irrlicht. - 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->setMax ( 12 );
gui.Tesselation->setSmallStep ( 1 ); gui.Tesselation->setSmallStep ( 1 );
gui.Tesselation->setLargeStep ( 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.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" ); 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 else
if ( eve.GUIEvent.Caller == gui.Tesselation && eve.GUIEvent.EventType == gui::EGET_SCROLL_BAR_CHANGED ) 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 else
if ( eve.GUIEvent.Caller == gui.Gamma && eve.GUIEvent.EventType == gui::EGET_SCROLL_BAR_CHANGED ) 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 #ifndef IRR_I_ANIMATED_MESH_H_INCLUDED
#define IRR_I_ANIMATED_MESH_H_INCLUDED #define IRR_I_ANIMATED_MESH_H_INCLUDED
#include "aabbox3d.h"
#include "IMesh.h" #include "IMesh.h"
namespace irr namespace irr

View File

@ -116,7 +116,7 @@ namespace scene
/** \return The aspect ratio of the camera. */ /** \return The aspect ratio of the camera. */
virtual f32 getAspectRatio() const =0; 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. */ /** \return The field of view of the camera in radians. */
virtual f32 getFOV() const =0; virtual f32 getFOV() const =0;
@ -135,7 +135,7 @@ namespace scene
\param aspect: New aspect ratio. */ \param aspect: New aspect ratio. */
virtual void setAspectRatio(f32 aspect) =0; 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. /** Also changes projection matrix and resets IsOrthogonal flag.
\param fovy: New field of view in radians. */ \param fovy: New field of view in radians. */
virtual void setFOV(f32 fovy) =0; virtual void setFOV(f32 fovy) =0;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -5,8 +5,6 @@
#ifndef IRR_I_SCENE_NODE_ANIMATOR_H_INCLUDED #ifndef IRR_I_SCENE_NODE_ANIMATOR_H_INCLUDED
#define 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 "ESceneNodeAnimatorTypes.h"
#include "IAttributeExchangingObject.h" #include "IAttributeExchangingObject.h"
#include "IAttributes.h" #include "IAttributes.h"

View File

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

View File

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

View File

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

View File

@ -195,13 +195,17 @@ public:
//! Lock function. //! Lock function.
/** Locks the Texture and returns a pointer to access the /** Locks the Texture and returns a pointer to access the
pixels. After lock() has been called and all operations on the pixels pixels. After lock() has been called and all operations on the pixels
are done, you must call unlock(). are done, you must call unlock(). Locks are not accumulating, hence one
Locks are not accumulating, hence one unlock will do for an arbitrary unlock will do for an arbitrary number of previous locks. You should avoid
number of previous locks. You should avoid locking different levels without locking different levels without unlocking in between, because only the
unlocking in between, though, because only the last level locked will be last level locked will be unlocked.
unlocked.
The size of the i-th mipmap level is defined as max(getSize().Width>>i,1) 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 \param mode Specifies what kind of changes to the locked texture are
allowed. Unspecified behavior will arise if texture is written in read allowed. Unspecified behavior will arise if texture is written in read
only mode or read from in write only mode. only mode or read from in write only mode.

View File

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

View File

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

View File

@ -303,20 +303,33 @@ namespace core
\return Returns false if there is no inverse matrix. */ \return Returns false if there is no inverse matrix. */
bool getInverse(CMatrix4<T>& out) const; 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 //! 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). //\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 //! 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 //! 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. //! Builds a right-handed perspective projection matrix.
CMatrix4<T>& buildProjectionMatrixPerspectiveRH(f32 widthOfViewVolume, f32 heightOfViewVolume, f32 zNear, f32 zFar, bool zClipFromZero=true); CMatrix4<T>& buildProjectionMatrixPerspectiveRH(f32 widthOfViewVolume, f32 heightOfViewVolume, f32 zNear, f32 zFar, bool zClipFromZero=true);
//! Builds a left-handed perspective projection matrix. //! 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); CMatrix4<T>& buildProjectionMatrixPerspectiveLH(f32 widthOfViewVolume, f32 heightOfViewVolume, f32 zNear, f32 zFar, bool zClipFromZero=true);
//! Builds a left-handed orthogonal projection matrix. //! Builds a left-handed orthogonal projection matrix.
@ -1568,101 +1581,69 @@ namespace core
} }
// Builds a right-handed perspective projection matrix based on a field of view // Builds a perspective projection matrix
template <class T> template <class T>
inline CMatrix4<T>& CMatrix4<T>::buildProjectionMatrixPerspectiveFovRH( inline CMatrix4<T>& CMatrix4<T>::buildProjectionMatrixPerspectiveFov(T sx, T sy, T zNear, T zFar, bool zClipFromZero, T zSign)
f32 fieldOfViewRadians, f32 aspectRatio, f32 zNear, f32 zFar, bool zClipFromZero)
{ {
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 IRR_DEBUG_BREAK_IF(zNear==zFar); //divide by zero
M[0] = w; M[0] = sx;
M[1] = 0; M[1] = 0;
M[2] = 0; M[2] = 0;
M[3] = 0; M[3] = 0;
M[4] = 0; M[4] = 0;
M[5] = (T)h; M[5] = sy;
M[6] = 0; M[6] = 0;
M[7] = 0; M[7] = 0;
M[8] = 0; M[8] = 0;
M[9] = 0; M[9] = 0;
//M[10] //M[10] below
M[11] = -1; M[11] = zSign;
M[12] = 0; M[12] = 0;
M[13] = 0; M[13] = 0;
//M[14] //M[14] below
M[15] = 0; M[15] = 0;
if ( zClipFromZero ) // DirectX version if ( zClipFromZero ) // DirectX version
{ {
M[10] = (T)(zFar/(zNear-zFar)); M[10] = zSign*zFar/(zFar-zNear);
M[14] = (T)(zNear*zFar/(zNear-zFar)); M[14] = (T)(zNear*zFar/(zNear-zFar));
} }
else // OpenGL version 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)); M[14] = (T)(2.0f*zNear*zFar/(zNear-zFar));
} }
#if defined ( USE_MATRIX_TEST ) #if defined ( USE_MATRIX_TEST )
definitelyIdentityMatrix=false; definitelyIdentityMatrix=false;
#endif #endif
return *this; 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 // Builds a left-handed perspective projection matrix based on a field of view
template <class T> template <class T>
inline CMatrix4<T>& CMatrix4<T>::buildProjectionMatrixPerspectiveFovLH( inline CMatrix4<T>& CMatrix4<T>::buildProjectionMatrixPerspectiveFovLH(
f32 fieldOfViewRadians, f32 aspectRatio, f32 zNear, f32 zFar, bool zClipFromZero) 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 IRR_DEBUG_BREAK_IF(aspectRatio==0.f); //divide by zero
const T w = static_cast<T>(h / aspectRatio); const T sx = static_cast<T>(sy / aspectRatio);
return buildProjectionMatrixPerspectiveFov(sx, static_cast<T>(sy), zNear, zFar, zClipFromZero, (T)1);
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;
}
// Builds a left-handed perspective projection matrix based on a field of view, with far plane culling at infinity // Builds a left-handed perspective projection matrix based on a field of view, with far plane culling at infinity
template <class T> template <class T>
@ -1791,7 +1772,6 @@ namespace core
return *this; return *this;
} }
// Builds a right-handed perspective projection matrix. // Builds a right-handed perspective projection matrix.
template <class T> template <class T>
inline CMatrix4<T>& CMatrix4<T>::buildProjectionMatrixPerspectiveRH( inline CMatrix4<T>& CMatrix4<T>::buildProjectionMatrixPerspectiveRH(
@ -1799,44 +1779,10 @@ namespace core
{ {
IRR_DEBUG_BREAK_IF(widthOfViewVolume==0.f); //divide by zero IRR_DEBUG_BREAK_IF(widthOfViewVolume==0.f); //divide by zero
IRR_DEBUG_BREAK_IF(heightOfViewVolume==0.f); //divide by zero IRR_DEBUG_BREAK_IF(heightOfViewVolume==0.f); //divide by zero
IRR_DEBUG_BREAK_IF(zNear==zFar); //divide by zero const T sx = (T)(2*zNear/widthOfViewVolume);
M[0] = (T)(2*zNear/widthOfViewVolume); const T sy = (T)(2*zNear/heightOfViewVolume);
M[1] = 0; return buildProjectionMatrixPerspectiveFov(sx, sy, zNear, zFar, zClipFromZero, (T)-1);
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;
}
// Builds a left-handed perspective projection matrix. // Builds a left-handed perspective projection matrix.
template <class T> template <class T>
@ -1845,42 +1791,10 @@ namespace core
{ {
IRR_DEBUG_BREAK_IF(widthOfViewVolume==0.f); //divide by zero IRR_DEBUG_BREAK_IF(widthOfViewVolume==0.f); //divide by zero
IRR_DEBUG_BREAK_IF(heightOfViewVolume==0.f); //divide by zero IRR_DEBUG_BREAK_IF(heightOfViewVolume==0.f); //divide by zero
IRR_DEBUG_BREAK_IF(zNear==zFar); //divide by zero const T sx = (T)(2*zNear/widthOfViewVolume);
M[0] = (T)(2*zNear/widthOfViewVolume); const T sy = (T)(2*zNear/heightOfViewVolume);
M[1] = 0;
M[2] = 0;
M[3] = 0;
M[4] = 0; return buildProjectionMatrixPerspectiveFov(sx, sy, zNear, zFar, zClipFromZero, (T)1);
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;
} }
@ -2399,4 +2313,3 @@ namespace core
} // end namespace irr } // end namespace irr
#endif #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. //! 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. */ \param center The center of the rotation. */
void rotateXZBy(f64 degrees, const vector3d<T>& center=vector3d<T>()) void rotateXZBy(f64 degrees, const vector3d<T>& center=vector3d<T>())
{ {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -13,7 +13,7 @@
#include "CMeshTextureLoader.h" #include "CMeshTextureLoader.h"
#include "IVideoDriver.h" #include "IVideoDriver.h"
#include "IFileSystem.h" #include "IAttributes.h"
#include "os.h" #include "os.h"
#ifdef _DEBUG #ifdef _DEBUG
@ -255,7 +255,7 @@ bool CB3DMeshFileLoader::readChunkMESH(CSkinnedMesh::SJoint *inJoint)
os::Printer::log(logStr.c_str(), ELL_DEBUG); os::Printer::log(logStr.c_str(), ELL_DEBUG);
#endif #endif
s32 brushID; s32 brushID=-1;
B3DFile->read(&brushID, sizeof(brushID)); B3DFile->read(&brushID, sizeof(brushID));
#ifdef __BIG_ENDIAN__ #ifdef __BIG_ENDIAN__
brushID = os::Byteswap::byteswap(brushID); brushID = os::Byteswap::byteswap(brushID);
@ -283,11 +283,15 @@ bool CB3DMeshFileLoader::readChunkMESH(CSkinnedMesh::SJoint *inJoint)
{ {
scene::SSkinMeshBuffer *meshBuffer = AnimatedMesh->addMeshBuffer(); scene::SSkinMeshBuffer *meshBuffer = AnimatedMesh->addMeshBuffer();
if (brushID!=-1) if ( brushID >= 0 && (u32)brushID < Materials.size() )
{ {
loadTextures(Materials[brushID]); loadTextures(Materials[brushID]);
meshBuffer->Material=Materials[brushID].Material; 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) if(readChunkTRIS(meshBuffer,AnimatedMesh->getMeshBuffers().size()-1, VerticesStart)==false)
return false; return false;
@ -364,7 +368,8 @@ bool CB3DMeshFileLoader::readChunkVRTS(CSkinnedMesh::SJoint *inJoint)
tex_coord_set_size = os::Byteswap::byteswap(tex_coord_set_size); tex_coord_set_size = os::Byteswap::byteswap(tex_coord_set_size);
#endif #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); os::Printer::log("tex_coord_sets or tex_coord_set_size too big", B3DFile->getFileName(), ELL_ERROR);
return false; return false;
@ -460,7 +465,7 @@ bool CB3DMeshFileLoader::readChunkTRIS(scene::SSkinMeshBuffer *meshBuffer, u32 m
bool showVertexWarning=false; 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)); B3DFile->read(&triangle_brush_id, sizeof(triangle_brush_id));
#ifdef __BIG_ENDIAN__ #ifdef __BIG_ENDIAN__
triangle_brush_id = os::Byteswap::byteswap(triangle_brush_id); triangle_brush_id = os::Byteswap::byteswap(triangle_brush_id);
@ -468,14 +473,20 @@ bool CB3DMeshFileLoader::readChunkTRIS(scene::SSkinMeshBuffer *meshBuffer, u32 m
SB3dMaterial *B3dMaterial; SB3dMaterial *B3dMaterial;
if (triangle_brush_id != -1) if (triangle_brush_id >= 0 && (u32)triangle_brush_id < Materials.size())
{ {
loadTextures(Materials[triangle_brush_id]); loadTextures(Materials[triangle_brush_id]);
B3dMaterial = &Materials[triangle_brush_id]; B3dMaterial = &Materials[triangle_brush_id];
meshBuffer->Material = B3dMaterial->Material; meshBuffer->Material = B3dMaterial->Material;
} }
else else
{
B3dMaterial = 0; 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); const s32 memoryNeeded = B3dStack.getLast().length / sizeof(s32);
meshBuffer->Indices.reallocate(memoryNeeded + meshBuffer->Indices.size() + 1); meshBuffer->Indices.reallocate(memoryNeeded + meshBuffer->Indices.size() + 1);
@ -594,7 +605,11 @@ bool CB3DMeshFileLoader::readChunkBONE(CSkinnedMesh::SJoint *inJoint)
#endif #endif
globalVertexID += VerticesStart; 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)"); 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) void CB3DMeshFileLoader::readString(core::stringc& newstring)
{ {
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) if (character==0)
return; return;
newstring.append(character); newstring.append(character);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -4,12 +4,11 @@
#include "CGUISpinBox.h" #include "CGUISpinBox.h"
#ifdef _IRR_COMPILE_WITH_GUI_ #ifdef _IRR_COMPILE_WITH_GUI_
#include "CGUIEditBox.h" #include "IGUIEditBox.h"
#include "CGUIButton.h" #include "IGUIButton.h"
#include "IGUIEnvironment.h" #include "IGUIEnvironment.h"
#include "IEventReceiver.h" #include "IEventReceiver.h"
#include "fast_atof.h" #include "fast_atof.h"
#include <wchar.h>
namespace irr namespace irr
@ -131,7 +130,7 @@ void CGUISpinBox::setRange(f32 min, f32 max)
RangeMin = min; RangeMin = min;
RangeMax = max; 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]; wchar_t str[100];
swprintf_irr(str, 99, FormatString.c_str(), RangeMin); swprintf_irr(str, 99, FormatString.c_str(), RangeMin);
RangeMin = core::fast_atof(core::stringc(str).c_str()); RangeMin = core::fast_atof(core::stringc(str).c_str());

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -11,7 +11,6 @@
#include "CColorConverter.h" #include "CColorConverter.h"
#include "CImage.h" #include "CImage.h"
#include "os.h" #include "os.h"
#include "irrString.h"
namespace irr 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 void CImageLoaderBMP::decompress8BitRLE(u8*& bmpData, s32 size, s32 width, s32 height, s32 pitch) const
{ {
u8* p = bmpData; u8* p = bmpData;
const u8* pEnd = bmpData + size;
u8* newBmp = new u8[(width+pitch)*height]; u8* newBmp = new u8[(width+pitch)*height];
u8* d = newBmp; u8* d = newBmp;
u8* destEnd = newBmp + (width+pitch)*height; const u8* destEnd = newBmp + (width+pitch)*height;
s32 line = 0; s32 line = 0;
while (bmpData - p < size && d < destEnd) while (p < pEnd && d < destEnd)
{ {
if (*p == 0) if (*p == 0)
{ {
++p; ++p;
EXIT_P_OVERFLOW(1);
switch(*p) switch(*p)
{ {
@ -70,37 +85,43 @@ void CImageLoaderBMP::decompress8BitRLE(u8*& bmpData, s32 size, s32 width, s32 h
d = newBmp + (line*(width+pitch)); d = newBmp + (line*(width+pitch));
break; break;
case 1: // end of bmp case 1: // end of bmp
delete [] bmpData; goto exit;
bmpData = newBmp;
return;
case 2: case 2:
++p; d +=(u8)*p; // delta ++p;
++p; d += ((u8)*p)*(width+pitch); EXIT_P_OVERFLOW(2);
d += (u8)*p; // delta
++p;
d += ((u8)*p)*(width+pitch);
++p; ++p;
break; break;
default: default:
{ {
// absolute mode // absolute mode
s32 count = (u8)*p; ++p; const s32 count = (u8)*p;
s32 readAdditional = ((2-(count%2))%2); ++p;
s32 i;
for (i=0; i<count; ++i) EXIT_P_OVERFLOW(count);
EXIT_D_OVERFLOW(count);
for (s32 i=0; i<count; ++i)
{ {
*d = *p; *d = *p;
++p; ++p;
++d; ++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; ++p;
} }
} }
} }
else else
{ {
s32 count = (u8)*p; ++p; const s32 count = (u8)*p; ++p;
EXIT_P_OVERFLOW(1);
u8 color = *p; ++p; u8 color = *p; ++p;
EXIT_D_OVERFLOW(count);
for (s32 i=0; i<count; ++i) for (s32 i=0; i<count; ++i)
{ {
*d = color; *d = color;
@ -109,63 +130,97 @@ void CImageLoaderBMP::decompress8BitRLE(u8*& bmpData, s32 size, s32 width, s32 h
} }
} }
exit:
delete [] bmpData; delete [] bmpData;
bmpData = newBmp; 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 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; u8* p = bmpData;
const u8* pEnd = bmpData + size;
u8* newBmp = new u8[lineWidth*height]; u8* newBmp = new u8[lineWidth*height];
u8* d = newBmp; memset(newBmp, 0, lineWidth*height); // Extra cost, but otherwise we have to code pixel skipping stuff
u8* destEnd = newBmp + lineWidth*height; const u8* destEnd = newBmp + lineWidth*height;
s32 line = 0; s32 line = 0;
s32 shift = 4; s32 row = 0;
while (bmpData - p < size && d < destEnd) while (p < pEnd)
{ {
if (*p == 0) if (*p == 0)
{ {
++p; ++p;
EXIT_P_OVERFLOW(1);
switch(*p) switch(*p)
{ {
case 0: // end of line case 0: // end of line
++p; ++p;
++line; ++line;
d = newBmp + (line*lineWidth); row = 0;
shift = 4;
break; break;
case 1: // end of bmp case 1: // end of bmp
delete [] bmpData; goto exit;
bmpData = newBmp; case 2: // delta
return;
case 2:
{ {
++p; ++p;
EXIT_P_OVERFLOW(2);
s32 x = (u8)*p; ++p; s32 x = (u8)*p; ++p;
s32 y = (u8)*p; ++p; s32 y = (u8)*p; ++p;
d += x/2 + y*lineWidth; row += x;
shift = x%2==0 ? 4 : 0; line += y;
} }
break; break;
default: default:
{ {
// absolute mode // absolute mode
s32 count = (u8)*p; ++p; const u32 count = (u8)*p; ++p;
s32 readAdditional = ((2-((count)%2))%2);
s32 readShift = 4; 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; s32 color = (((u8)*p) >> readShift) & 0x0f;
readShift -= 4; readShift -= 4;
if (readShift < 0) if (readShift < 0)
{ {
++*p; ++p;
readShift = 4; readShift = 4;
} }
@ -178,26 +233,37 @@ void CImageLoaderBMP::decompress4BitRLE(u8*& bmpData, s32 size, s32 width, s32 h
shift = 4; shift = 4;
++d; ++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; ++p;
} }
} }
} }
else else // encoded mode
{ {
s32 count = (u8)*p; ++p; const s32 count = (u8)*p; // pixels to draw
s32 color1 = (u8)*p; color1 = color1 & 0x0f; ++p;
s32 color2 = (u8)*p; color2 = (color2 >> 4) & 0x0f; 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; ++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) for (s32 i=0; i<count; ++i)
{ {
u8 mask = 0x0f << shift; u8 mask = 0x0f << shift;
u8 toSet = (shift==0 ? color1 : color2) << shift; u8 toSet = ((i%2==0) ? color2 : color1) << shift;
*d = (*d & (~mask)) | (toSet & mask); *d = (*d & (~mask)) | toSet;
shift -= 4; shift -= 4;
if (shift < 0) if (shift < 0)
@ -206,14 +272,18 @@ void CImageLoaderBMP::decompress4BitRLE(u8*& bmpData, s32 size, s32 width, s32 h
++d; ++d;
} }
} }
row += count;
} }
} }
exit:
delete [] bmpData; delete [] bmpData;
bmpData = newBmp; bmpData = newBmp;
} }
#undef EXIT_P_OVERFLOW
#undef EXIT_D_OVERFLOW
#undef KEEP_ROW_LINE_INSIDE
//! creates a surface from the file //! creates a surface from the file
IImage* CImageLoaderBMP::loadImage(io::IReadFile* file) const 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); header.ImportantColors = os::Byteswap::byteswap(header.ImportantColors);
#endif #endif
s32 pitch = 0;
//! return if the header is false //! 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; return 0;
}
if (header.Compression > 2) // we'll only handle RLE-Compression 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); file->seek(header.BitmapDataOffset);
f32 t = (header.Width) * (header.BPP / 8.0f); const s32 widthInBytes = core::ceil32(header.Width * (header.BPP / 8.0f));
s32 widthInBytes = (s32)t; const s32 lineSize = widthInBytes + ((4-(widthInBytes%4)))%4;
t -= widthInBytes; const s32 pitch = lineSize - widthInBytes;
if (t!=0.0f)
++widthInBytes;
s32 lineData = widthInBytes + ((4-(widthInBytes%4)))%4;
pitch = lineData - widthInBytes;
u8* bmpData = new u8[header.BitmapDataSize]; u8* bmpData = new u8[header.BitmapDataSize];
file->read(bmpData, header.BitmapDataSize); file->read(bmpData, header.BitmapDataSize);
@ -297,14 +375,25 @@ IImage* CImageLoaderBMP::loadImage(io::IReadFile* file) const
// decompress data if needed // decompress data if needed
switch(header.Compression) switch(header.Compression)
{ {
case 1: // 8 bit rle case 1: // 8 bit RLE
decompress8BitRLE(bmpData, header.BitmapDataSize, header.Width, header.Height, pitch); decompress8BitRLE(bmpData, header.BitmapDataSize, header.Width, header.Height, pitch);
header.BitmapDataSize = (header.Width + pitch) * header.Height;
break; break;
case 2: // 4 bit rle case 2: // 4 bit RLE
decompress4BitRLE(bmpData, header.BitmapDataSize, header.Width, header.Height, pitch); decompress4BitRLE(bmpData, header.BitmapDataSize, header.Width, header.Height, pitch);
header.BitmapDataSize = ((header.Width+1)/2 + pitch) * header.Height;
break; 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 // create surface
// no default constructor from packed area! ARM problem! // no default constructor from packed area! ARM problem!
@ -359,6 +448,9 @@ cleanup:
delete [] paletteData; delete [] paletteData;
delete [] bmpData; delete [] bmpData;
if ( image && topDown )
image->flip(true, false);
return image; return image;
} }

View File

@ -18,9 +18,7 @@
#include "IReadFile.h" #include "IReadFile.h"
#include "os.h" #include "os.h"
#include "CColorConverter.h"
#include "CImage.h" #include "CImage.h"
#include "irrString.h"
// Header flag values // Header flag values
#define DDSD_CAPS 0x00000001 #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)); 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->drop();
image = 0; image = 0;
} }

View File

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

View File

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

View File

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

View File

@ -9,7 +9,6 @@
#include "IReadFile.h" #include "IReadFile.h"
#include "os.h" #include "os.h"
#include "CImage.h" #include "CImage.h"
#include "irrString.h"
namespace irr 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 "CColorConverter.h"
#include "CImage.h" #include "CImage.h"
#include "os.h" #include "os.h"
#include "irrString.h"
namespace irr namespace irr

View File

@ -10,7 +10,6 @@
#include "os.h" #include "os.h"
#include "CColorConverter.h" #include "CColorConverter.h"
#include "CImage.h" #include "CImage.h"
#include "irrString.h"
namespace irr 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! // This was written and sent in by Jon Pry, thank you very much!
// I only changed the formatting a little bit. // I only changed the formatting a little bit.
s32 bytesPerPixel = header.PixelDepth/8; const u32 bytesPerPixel = header.PixelDepth/8;
s32 imageSize = header.ImageHeight * header.ImageWidth * bytesPerPixel; const u32 imageSize = header.ImageHeight * header.ImageWidth * bytesPerPixel;
u8* data = new u8[imageSize]; u8* data = new u8[imageSize];
s32 currentByte = 0; u32 currentByte = 0;
while(currentByte < imageSize) 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 chunkheader++; // Add 1 To The Value To Get Total Number Of Raw Pixels
file->read(&data[currentByte], bytesPerPixel * chunkheader); const u32 bytesToRead = bytesPerPixel * chunkheader;
currentByte += 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 else
{ {
@ -57,15 +65,27 @@ u8 *CImageLoaderTGA::loadCompressedImage(io::IReadFile *file, const STGAHeader&
// If It's An RLE Header // If It's An RLE Header
chunkheader -= 127; // Subtract 127 To Get Rid Of The ID Bit chunkheader -= 127; // Subtract 127 To Get Rid Of The ID Bit
s32 dataOffset = currentByte; u32 dataOffset = currentByte;
file->read(&data[dataOffset], bytesPerPixel); if ( dataOffset+bytesPerPixel < imageSize )
{
currentByte += bytesPerPixel; file->read(&data[dataOffset], bytesPerPixel);
currentByte += bytesPerPixel;
for(s32 counter = 1; counter < chunkheader; counter++) }
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++)
{ {
for(s32 elementCounter=0; elementCounter < bytesPerPixel; elementCounter++)
data[currentByte + elementCounter] = data[dataOffset + elementCounter]; data[currentByte + elementCounter] = data[dataOffset + elementCounter];
}
}
currentByte += bytesPerPixel; currentByte += bytesPerPixel;
} }
@ -118,8 +138,17 @@ IImage* CImageLoaderTGA::loadImage(io::IReadFile* file) const
if (header.ColorMapType) if (header.ColorMapType)
{ {
// create 32 bit palette // Create 32 bit palette
palette = new u32[ header.ColorMapLength]; 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 // read color map
u8 * colorMap = new u8[header.ColorMapEntrySize/8 * header.ColorMapLength]; 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 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]; data = new u8[imageSize];
file->read(data, imageSize); file->read(data, imageSize);
} }
@ -185,14 +214,28 @@ IImage* CImageLoaderTGA::loadImage(io::IReadFile* file) const
} }
else else
{ {
image = new CImage(ECF_A1R5G5B5, switch ( header.ColorMapEntrySize )
core::dimension2d<u32>(header.ImageWidth, header.ImageHeight)); {
if (image) case 16:
image = new CImage(ECF_A1R5G5B5, core::dimension2d<u32>(header.ImageWidth, header.ImageHeight));
if ( image )
CColorConverter::convert8BitTo16Bit((u8*)data, CColorConverter::convert8BitTo16Bit((u8*)data,
(s16*)image->getData(), (s16*)image->getData(),
header.ImageWidth,header.ImageHeight, header.ImageWidth,header.ImageHeight,
(s32*) palette, 0, (s32*) palette, 0,
(header.ImageDescriptor&0x20)==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; break;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -9,8 +9,6 @@
#ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_ #ifdef _IRR_COMPILE_WITH_WINDOWS_DEVICE_
#include "CIrrDeviceStub.h" #include "CIrrDeviceStub.h"
#include "IrrlichtDevice.h"
#include "IImagePresenter.h"
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#if !defined(_IRR_XBOX_PLATFORM_) #if !defined(_IRR_XBOX_PLATFORM_)
@ -71,7 +69,7 @@ namespace irr
virtual video::IVideoModeList* getVideoModeList() IRR_OVERRIDE; virtual video::IVideoModeList* getVideoModeList() IRR_OVERRIDE;
//! Notifies the device, that it has been resized //! 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(); void OnResized();
//! Sets if the window should be resizable in windowed mode. //! Sets if the window should be resizable in windowed mode.

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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