]> git.lizzy.rs Git - irrlicht.git/blobdiff - source/Irrlicht/CNullDriver.cpp
Resolve conflicts with master
[irrlicht.git] / source / Irrlicht / CNullDriver.cpp
index 23110e33bdf5a6ff9d0bd09b1efd4cb039f53cb5..a02431cf8f51b44d2032619129786a05d6d53bc7 100644 (file)
@@ -14,7 +14,7 @@
 #include "IAnimatedMeshSceneNode.h"\r
 #include "CMeshManipulator.h"\r
 #include "CColorConverter.h"\r
-#include "IAttributeExchangingObject.h"\r
+#include "IReferenceCounted.h"\r
 #include "IRenderTarget.h"\r
 \r
 \r
@@ -32,57 +32,15 @@ IImageLoader* createImageLoaderJPG();
 //! creates a loader which is able to load targa images\r
 IImageLoader* createImageLoaderTGA();\r
 \r
-//! creates a loader which is able to load psd images\r
-IImageLoader* createImageLoaderPSD();\r
-\r
-//! creates a loader which is able to load psd images\r
-IImageLoader* createImageLoaderPVR();\r
-\r
-//! creates a loader which is able to load dds images\r
-IImageLoader* createImageLoaderDDS();\r
-\r
-//! creates a loader which is able to load pcx images\r
-IImageLoader* createImageLoaderPCX();\r
-\r
 //! creates a loader which is able to load png images\r
 IImageLoader* createImageLoaderPNG();\r
 \r
-//! creates a loader which is able to load WAL images\r
-IImageLoader* createImageLoaderWAL();\r
-\r
-//! creates a loader which is able to load halflife images\r
-IImageLoader* createImageLoaderHalfLife();\r
-\r
-//! creates a loader which is able to load lmp images\r
-IImageLoader* createImageLoaderLMP();\r
-\r
-//! creates a loader which is able to load ppm/pgm/pbm images\r
-IImageLoader* createImageLoaderPPM();\r
-\r
-//! creates a loader which is able to load rgb images\r
-IImageLoader* createImageLoaderRGB();\r
-\r
-\r
-//! creates a writer which is able to save bmp images\r
-IImageWriter* createImageWriterBMP();\r
-\r
 //! creates a writer which is able to save jpg images\r
 IImageWriter* createImageWriterJPG();\r
 \r
-//! creates a writer which is able to save tga images\r
-IImageWriter* createImageWriterTGA();\r
-\r
-//! creates a writer which is able to save psd images\r
-IImageWriter* createImageWriterPSD();\r
-\r
-//! creates a writer which is able to save pcx images\r
-IImageWriter* createImageWriterPCX();\r
-\r
 //! creates a writer which is able to save png images\r
 IImageWriter* createImageWriterPNG();\r
 \r
-//! creates a writer which is able to save ppm images\r
-IImageWriter* createImageWriterPPM();\r
 \r
 //! constructor\r
 CNullDriver::CNullDriver(io::IFileSystem* io, const core::dimension2d<u32>& screenSize)\r
@@ -95,9 +53,8 @@ CNullDriver::CNullDriver(io::IFileSystem* io, const core::dimension2d<u32>& scre
        #endif\r
 \r
        DriverAttributes = new io::CAttributes();\r
-       DriverAttributes->addInt("MaxTextures", _IRR_MATERIAL_MAX_TEXTURES_);\r
-       DriverAttributes->addInt("MaxSupportedTextures", _IRR_MATERIAL_MAX_TEXTURES_);\r
-       DriverAttributes->addInt("MaxLights", getMaximalDynamicLightAmount());\r
+       DriverAttributes->addInt("MaxTextures", MATERIAL_MAX_TEXTURES);\r
+       DriverAttributes->addInt("MaxSupportedTextures", MATERIAL_MAX_TEXTURES);\r
        DriverAttributes->addInt("MaxAnisotropy", 1);\r
 //     DriverAttributes->addInt("MaxUserClipPlanes", 0);\r
 //     DriverAttributes->addInt("MaxAuxBuffers", 0);\r
@@ -125,72 +82,18 @@ CNullDriver::CNullDriver(io::IFileSystem* io, const core::dimension2d<u32>& scre
        if (FileSystem)\r
                FileSystem->grab();\r
 \r
-       // create surface loader\r
-\r
-#ifdef _IRR_COMPILE_WITH_WAL_LOADER_\r
-       SurfaceLoader.push_back(video::createImageLoaderHalfLife());\r
-       SurfaceLoader.push_back(video::createImageLoaderWAL());\r
-#endif\r
-#ifdef _IRR_COMPILE_WITH_LMP_LOADER_\r
-       SurfaceLoader.push_back(video::createImageLoaderLMP());\r
-#endif\r
-#ifdef _IRR_COMPILE_WITH_PPM_LOADER_\r
-       SurfaceLoader.push_back(video::createImageLoaderPPM());\r
-#endif\r
-#ifdef _IRR_COMPILE_WITH_RGB_LOADER_\r
-       SurfaceLoader.push_back(video::createImageLoaderRGB());\r
-#endif\r
-#ifdef _IRR_COMPILE_WITH_PSD_LOADER_\r
-       SurfaceLoader.push_back(video::createImageLoaderPSD());\r
-#endif\r
-#ifdef _IRR_COMPILE_WITH_PVR_LOADER_\r
-       SurfaceLoader.push_back(video::createImageLoaderPVR());\r
-#endif\r
-#if defined(_IRR_COMPILE_WITH_DDS_LOADER_) || defined(_IRR_COMPILE_WITH_DDS_DECODER_LOADER_)\r
-       SurfaceLoader.push_back(video::createImageLoaderDDS());\r
-#endif\r
-#ifdef _IRR_COMPILE_WITH_PCX_LOADER_\r
-       SurfaceLoader.push_back(video::createImageLoaderPCX());\r
-#endif\r
-#ifdef _IRR_COMPILE_WITH_TGA_LOADER_\r
+       // create surface loaders and writers\r
        SurfaceLoader.push_back(video::createImageLoaderTGA());\r
-#endif\r
-#ifdef _IRR_COMPILE_WITH_PNG_LOADER_\r
        SurfaceLoader.push_back(video::createImageLoaderPNG());\r
-#endif\r
-#ifdef _IRR_COMPILE_WITH_JPG_LOADER_\r
        SurfaceLoader.push_back(video::createImageLoaderJPG());\r
-#endif\r
-#ifdef _IRR_COMPILE_WITH_BMP_LOADER_\r
        SurfaceLoader.push_back(video::createImageLoaderBMP());\r
-#endif\r
-\r
-\r
-#ifdef _IRR_COMPILE_WITH_PPM_WRITER_\r
-       SurfaceWriter.push_back(video::createImageWriterPPM());\r
-#endif\r
-#ifdef _IRR_COMPILE_WITH_PCX_WRITER_\r
-       SurfaceWriter.push_back(video::createImageWriterPCX());\r
-#endif\r
-#ifdef _IRR_COMPILE_WITH_PSD_WRITER_\r
-       SurfaceWriter.push_back(video::createImageWriterPSD());\r
-#endif\r
-#ifdef _IRR_COMPILE_WITH_TGA_WRITER_\r
-       SurfaceWriter.push_back(video::createImageWriterTGA());\r
-#endif\r
-#ifdef _IRR_COMPILE_WITH_JPG_WRITER_\r
+\r
        SurfaceWriter.push_back(video::createImageWriterJPG());\r
-#endif\r
-#ifdef _IRR_COMPILE_WITH_PNG_WRITER_\r
        SurfaceWriter.push_back(video::createImageWriterPNG());\r
-#endif\r
-#ifdef _IRR_COMPILE_WITH_BMP_WRITER_\r
-       SurfaceWriter.push_back(video::createImageWriterBMP());\r
-#endif\r
 \r
 \r
        // set ExposedData to 0\r
-       memset(&ExposedData, 0, sizeof(ExposedData));\r
+       memset((void*)&ExposedData, 0, sizeof(ExposedData));\r
        for (u32 i=0; i<video::EVDF_COUNT; ++i)\r
                FeatureEnabled[i]=true;\r
 \r
@@ -725,7 +628,9 @@ video::ITexture* CNullDriver::findTexture(const io::path& filename)
 \r
 ITexture* CNullDriver::createDeviceDependentTexture(const io::path& name, IImage* image)\r
 {\r
-       return new SDummyTexture(name, ETT_2D);\r
+       SDummyTexture* dummy = new SDummyTexture(name, ETT_2D);\r
+       dummy->setSize(image->getDimension());\r
+       return dummy;\r
 }\r
 \r
 ITexture* CNullDriver::createDeviceDependentTextureCubemap(const io::path& name, const core::array<IImage*>& image)\r
@@ -814,27 +719,6 @@ void CNullDriver::draw3DLine(const core::vector3df& start,
 }\r
 \r
 \r
-//! Draws a 3d triangle.\r
-void CNullDriver::draw3DTriangle(const core::triangle3df& triangle, SColor color)\r
-{\r
-       S3DVertex vertices[3];\r
-       vertices[0].Pos=triangle.pointA;\r
-       vertices[0].Color=color;\r
-       vertices[0].Normal=triangle.getNormal().normalize();\r
-       vertices[0].TCoords.set(0.f,0.f);\r
-       vertices[1].Pos=triangle.pointB;\r
-       vertices[1].Color=color;\r
-       vertices[1].Normal=vertices[0].Normal;\r
-       vertices[1].TCoords.set(0.5f,1.f);\r
-       vertices[2].Pos=triangle.pointC;\r
-       vertices[2].Color=color;\r
-       vertices[2].Normal=vertices[0].Normal;\r
-       vertices[2].TCoords.set(1.f,0.f);\r
-       const u16 indexList[] = {0,1,2};\r
-       drawVertexPrimitiveList(vertices, 3, indexList, 1, EVT_STANDARD, scene::EPT_TRIANGLES, EIT_16BIT);\r
-}\r
-\r
-\r
 //! Draws a 3d axis aligned box.\r
 void CNullDriver::draw3DBox(const core::aabbox3d<f32>& box, SColor color)\r
 {\r
@@ -867,38 +751,13 @@ void CNullDriver::draw2DImage(const video::ITexture* texture, const core::positi
 \r
        draw2DImage(texture,destPos, core::rect<s32>(core::position2d<s32>(0,0),\r
                                                                                                core::dimension2di(texture->getOriginalSize())),\r
-                                                                                               0, \r
-                                                                                               SColor(255,255,255,255), \r
+                                                                                               0,\r
+                                                                                               SColor(255,255,255,255),\r
                                                                                                useAlphaChannelOfTexture\r
                                                                                                );\r
 }\r
 \r
 \r
-\r
-//! draws a set of 2d images, using a color and the alpha channel of the\r
-//! texture if desired. The images are drawn beginning at pos and concatenated\r
-//! in one line. All drawings are clipped against clipRect (if != 0).\r
-//! The subtextures are defined by the array of sourceRects and are chosen\r
-//! by the indices given.\r
-void CNullDriver::draw2DImageBatch(const video::ITexture* texture,\r
-                               const core::position2d<s32>& pos,\r
-                               const core::array<core::rect<s32> >& sourceRects,\r
-                               const core::array<s32>& indices,\r
-                               s32 kerningWidth,\r
-                               const core::rect<s32>* clipRect, SColor color,\r
-                               bool useAlphaChannelOfTexture)\r
-{\r
-       core::position2d<s32> target(pos);\r
-\r
-       for (u32 i=0; i<indices.size(); ++i)\r
-       {\r
-               draw2DImage(texture, target, sourceRects[indices[i]],\r
-                               clipRect, color, useAlphaChannelOfTexture);\r
-               target.X += sourceRects[indices[i]].getWidth();\r
-               target.X += kerningWidth;\r
-       }\r
-}\r
-\r
 //! draws a set of 2d images, using a color and the alpha channel of the\r
 //! texture if desired.\r
 void CNullDriver::draw2DImageBatch(const video::ITexture* texture,\r
@@ -939,16 +798,6 @@ void CNullDriver::draw2DImage(const video::ITexture* texture, const core::positi
 }\r
 \r
 \r
-//! Draws the outline of a 2d rectangle\r
-void CNullDriver::draw2DRectangleOutline(const core::recti& pos, SColor color)\r
-{\r
-       draw2DLine(pos.UpperLeftCorner, core::position2di(pos.LowerRightCorner.X, pos.UpperLeftCorner.Y), color);\r
-       draw2DLine(core::position2di(pos.LowerRightCorner.X, pos.UpperLeftCorner.Y), pos.LowerRightCorner, color);\r
-       draw2DLine(pos.LowerRightCorner, core::position2di(pos.UpperLeftCorner.X, pos.LowerRightCorner.Y), color);\r
-       draw2DLine(core::position2di(pos.UpperLeftCorner.X, pos.LowerRightCorner.Y), pos.UpperLeftCorner, color);\r
-}\r
-\r
-\r
 //! Draw a 2d rectangle\r
 void CNullDriver::draw2DRectangle(SColor color, const core::rect<s32>& pos, const core::rect<s32>* clip)\r
 {\r
@@ -972,38 +821,6 @@ void CNullDriver::draw2DLine(const core::position2d<s32>& start,
 {\r
 }\r
 \r
-//! Draws a pixel\r
-void CNullDriver::drawPixel(u32 x, u32 y, const SColor & color)\r
-{\r
-}\r
-\r
-\r
-//! Draws a non filled concyclic regular 2d polygon.\r
-void CNullDriver::draw2DPolygon(core::position2d<s32> center,\r
-       f32 radius, video::SColor color, s32 count)\r
-{\r
-       if (count < 2)\r
-               return;\r
-\r
-       core::position2d<s32> first;\r
-       core::position2d<s32> a,b;\r
-\r
-       for (s32 j=0; j<count; ++j)\r
-       {\r
-               b = a;\r
-\r
-               f32 p = j / (f32)count * (core::PI*2);\r
-               a = center + core::position2d<s32>((s32)(sin(p)*radius), (s32)(cos(p)*radius));\r
-\r
-               if (j==0)\r
-                       first = a;\r
-               else\r
-                       draw2DLine(a, b, color);\r
-       }\r
-\r
-       draw2DLine(a, first, color);\r
-}\r
-\r
 \r
 //! returns color format\r
 ECOLOR_FORMAT CNullDriver::getColorFormat() const\r
@@ -1074,80 +891,6 @@ const wchar_t* CNullDriver::getName() const
 }\r
 \r
 \r
-\r
-//! Draws a shadow volume into the stencil buffer. To draw a stencil shadow, do\r
-//! this: Frist, draw all geometry. Then use this method, to draw the shadow\r
-//! volume. Then, use IVideoDriver::drawStencilShadow() to visualize the shadow.\r
-void CNullDriver::drawStencilShadowVolume(const core::array<core::vector3df>& triangles, bool zfail, u32 debugDataVisible)\r
-{\r
-}\r
-\r
-\r
-//! Fills the stencil shadow with color. After the shadow volume has been drawn\r
-//! into the stencil buffer using IVideoDriver::drawStencilShadowVolume(), use this\r
-//! to draw the color of the shadow.\r
-void CNullDriver::drawStencilShadow(bool clearStencilBuffer,\r
-               video::SColor leftUpEdge, video::SColor rightUpEdge,\r
-               video::SColor leftDownEdge, video::SColor rightDownEdge)\r
-{\r
-}\r
-\r
-\r
-//! deletes all dynamic lights there are\r
-void CNullDriver::deleteAllDynamicLights()\r
-{\r
-       Lights.set_used(0);\r
-}\r
-\r
-\r
-//! adds a dynamic light\r
-s32 CNullDriver::addDynamicLight(const SLight& light)\r
-{\r
-       Lights.push_back(light);\r
-       return Lights.size() - 1;\r
-}\r
-\r
-//! Turns a dynamic light on or off\r
-//! \param lightIndex: the index returned by addDynamicLight\r
-//! \param turnOn: true to turn the light on, false to turn it off\r
-void CNullDriver::turnLightOn(s32 lightIndex, bool turnOn)\r
-{\r
-       // Do nothing\r
-}\r
-\r
-\r
-//! returns the maximal amount of dynamic lights the device can handle\r
-u32 CNullDriver::getMaximalDynamicLightAmount() const\r
-{\r
-       return 0;\r
-}\r
-\r
-\r
-//! Returns current amount of dynamic lights set\r
-//! \return Current amount of dynamic lights set\r
-u32 CNullDriver::getDynamicLightCount() const\r
-{\r
-       return Lights.size();\r
-}\r
-\r
-\r
-//! Returns light data which was previously set by IVideoDriver::addDynamicLight().\r
-//! \param idx: Zero based index of the light. Must be greater than 0 and smaller\r
-//! than IVideoDriver()::getDynamicLightCount.\r
-//! \return Light data.\r
-const SLight& CNullDriver::getDynamicLight(u32 idx) const\r
-{\r
-       if ( idx < Lights.size() )\r
-               return Lights[idx];\r
-       else\r
-       {\r
-               _IRR_DEBUG_BREAK_IF(true)\r
-               static const SLight dummy;\r
-               return dummy;\r
-       }\r
-}\r
-\r
-\r
 //! Creates a boolean alpha channel of the texture based of an color key.\r
 void CNullDriver::makeColorKeyTexture(video::ITexture* texture,\r
                                                                        video::SColor color,\r
@@ -1289,124 +1032,6 @@ void CNullDriver::makeColorKeyTexture(video::ITexture* texture,
 }\r
 \r
 \r
-\r
-//! Creates a normal map from a height map texture.\r
-//! \param amplitude: Constant value by which the height information is multiplied.\r
-void CNullDriver::makeNormalMapTexture(video::ITexture* texture, f32 amplitude) const\r
-{\r
-       if (!texture)\r
-               return;\r
-\r
-       if (texture->getColorFormat() != ECF_A1R5G5B5 &&\r
-               texture->getColorFormat() != ECF_A8R8G8B8 )\r
-       {\r
-               os::Printer::log("Error: Unsupported texture color format for making normal map.", ELL_ERROR);\r
-               return;\r
-       }\r
-\r
-       core::dimension2d<u32> dim = texture->getSize();\r
-       amplitude = amplitude / 255.0f;\r
-       f32 vh = dim.Height / (f32)dim.Width;\r
-       f32 hh = dim.Width / (f32)dim.Height;\r
-\r
-       if (texture->getColorFormat() == ECF_A8R8G8B8)\r
-       {\r
-               // ECF_A8R8G8B8 version\r
-\r
-               s32 *p = (s32*)texture->lock();\r
-\r
-               if (!p)\r
-               {\r
-                       os::Printer::log("Could not lock texture for making normal map.", ELL_ERROR);\r
-                       return;\r
-               }\r
-\r
-               // copy texture\r
-\r
-               u32 pitch = texture->getPitch() / 4;\r
-\r
-               s32* in = new s32[dim.Height * pitch];\r
-               memcpy(in, p, dim.Height * pitch * 4);\r
-\r
-               for (s32 x=0; x < s32(pitch); ++x)\r
-                       for (s32 y=0; y < s32(dim.Height); ++y)\r
-                       {\r
-                               // TODO: this could be optimized really a lot\r
-\r
-                               core::vector3df h1((x-1)*hh, nml32(x-1, y, pitch, dim.Height, in)*amplitude, y*vh);\r
-                               core::vector3df h2((x+1)*hh, nml32(x+1, y, pitch, dim.Height, in)*amplitude, y*vh);\r
-                               //core::vector3df v1(x*hh, nml32(x, y-1, pitch, dim.Height, in)*amplitude, (y-1)*vh);\r
-                               //core::vector3df v2(x*hh, nml32(x, y+1, pitch, dim.Height, in)*amplitude, (y+1)*vh);\r
-                               core::vector3df v1(x*hh, nml32(x, y+1, pitch, dim.Height, in)*amplitude, (y-1)*vh);\r
-                               core::vector3df v2(x*hh, nml32(x, y-1, pitch, dim.Height, in)*amplitude, (y+1)*vh);\r
-\r
-                               core::vector3df v = v1-v2;\r
-                               core::vector3df h = h1-h2;\r
-\r
-                               core::vector3df n = v.crossProduct(h);\r
-                               n.normalize();\r
-                               n *= 0.5f;\r
-                               n += core::vector3df(0.5f,0.5f,0.5f); // now between 0 and 1\r
-                               n *= 255.0f;\r
-\r
-                               s32 height = (s32)nml32(x, y, pitch, dim.Height, in);\r
-                               p[y*pitch + x] = video::SColor(\r
-                                       height, // store height in alpha\r
-                                       (s32)n.X, (s32)n.Z, (s32)n.Y).color;\r
-                       }\r
-\r
-               delete [] in;\r
-               texture->unlock();\r
-       }\r
-       else\r
-       {\r
-               // ECF_A1R5G5B5 version\r
-\r
-               s16 *p = (s16*)texture->lock();\r
-\r
-               if (!p)\r
-               {\r
-                       os::Printer::log("Could not lock texture for making normal map.", ELL_ERROR);\r
-                       return;\r
-               }\r
-\r
-               u32 pitch = texture->getPitch() / 2;\r
-\r
-               // copy texture\r
-\r
-               s16* in = new s16[dim.Height * pitch];\r
-               memcpy(in, p, dim.Height * pitch * 2);\r
-\r
-               for (s32 x=0; x < s32(pitch); ++x)\r
-                       for (s32 y=0; y < s32(dim.Height); ++y)\r
-                       {\r
-                               // TODO: this could be optimized really a lot\r
-\r
-                               core::vector3df h1((x-1)*hh, nml16(x-1, y, pitch, dim.Height, in)*amplitude, y*vh);\r
-                               core::vector3df h2((x+1)*hh, nml16(x+1, y, pitch, dim.Height, in)*amplitude, y*vh);\r
-                               core::vector3df v1(x*hh, nml16(x, y-1, pitch, dim.Height, in)*amplitude, (y-1)*vh);\r
-                               core::vector3df v2(x*hh, nml16(x, y+1, pitch, dim.Height, in)*amplitude, (y+1)*vh);\r
-\r
-                               core::vector3df v = v1-v2;\r
-                               core::vector3df h = h1-h2;\r
-\r
-                               core::vector3df n = v.crossProduct(h);\r
-                               n.normalize();\r
-                               n *= 0.5f;\r
-                               n += core::vector3df(0.5f,0.5f,0.5f); // now between 0 and 1\r
-                               n *= 255.0f;\r
-\r
-                               p[y*pitch + x] = video::RGBA16((u32)n.X, (u32)n.Z, (u32)n.Y);\r
-                       }\r
-\r
-               delete [] in;\r
-               texture->unlock();\r
-       }\r
-\r
-       texture->regenerateMipMapLevels();\r
-}\r
-\r
-\r
 //! Returns the maximum amount of primitives (mostly vertices) which\r
 //! the device is able to render with one drawIndexedTriangleList\r
 //! call.\r
@@ -1423,8 +1048,8 @@ bool CNullDriver::checkPrimitiveCount(u32 prmCount) const
 \r
        if (prmCount > m)\r
        {\r
-               char tmp[1024];\r
-               sprintf(tmp,"Could not draw triangles, too many primitives(%u), maximum is %u.", prmCount, m);\r
+               char tmp[128];\r
+               snprintf_irr(tmp, sizeof(tmp), "Could not draw triangles, too many primitives(%u), maximum is %u.", prmCount, m);\r
                os::Printer::log(tmp, ELL_ERROR);\r
                return false;\r
        }\r
@@ -1603,7 +1228,9 @@ core::array<IImage*> CNullDriver::createImagesFromFile(io::IReadFile* file, E_TE
                {\r
                        // dito\r
                        file->seek(0);\r
-                       if (SurfaceLoader[i]->isALoadableFileFormat(file))\r
+                       if (SurfaceLoader[i]->isALoadableFileFormat(file)\r
+                               && !SurfaceLoader[i]->isALoadableFileExtension(file->getFileName())     // extension was tried above already\r
+                               )\r
                        {\r
                                file->seek(0);\r
                                imageArray = SurfaceLoader[i]->loadImages(file, type);\r
@@ -1803,9 +1430,9 @@ CNullDriver::SHWBufferLink *CNullDriver::getBufferLink(const scene::IMeshBuffer*
                return 0;\r
 \r
        //search for hardware links\r
-       core::map< const scene::IMeshBuffer*,SHWBufferLink* >::Node* node = HWBufferMap.find(mb);\r
-       if (node)\r
-               return node->getValue();\r
+       SHWBufferLink *HWBuffer = reinterpret_cast<SHWBufferLink*>(mb->getHWBuffer());\r
+       if (HWBuffer)\r
+               return HWBuffer;\r
 \r
        return createHardwareBuffer(mb); //no hardware links, and mesh wants one, create it\r
 }\r
@@ -1814,20 +1441,13 @@ CNullDriver::SHWBufferLink *CNullDriver::getBufferLink(const scene::IMeshBuffer*
 //! Update all hardware buffers, remove unused ones\r
 void CNullDriver::updateAllHardwareBuffers()\r
 {\r
-       core::map<const scene::IMeshBuffer*,SHWBufferLink*>::ParentFirstIterator Iterator=HWBufferMap.getParentFirstIterator();\r
-\r
-       for (;!Iterator.atEnd();Iterator++)\r
-       {\r
-               SHWBufferLink *Link=Iterator.getNode()->getValue();\r
+       auto it = HWBufferList.begin();\r
+       while (it != HWBufferList.end()) {\r
+               SHWBufferLink *Link = *it;\r
+               ++it;\r
 \r
-               Link->LastUsed++;\r
-               if (Link->LastUsed>20000)\r
-               {\r
+               if (!Link->MeshBuffer || Link->MeshBuffer->getReferenceCount() == 1)\r
                        deleteHardwareBuffer(Link);\r
-\r
-                       // todo: needs better fix\r
-                       Iterator = HWBufferMap.getParentFirstIterator();\r
-               }\r
        }\r
 }\r
 \r
@@ -1836,7 +1456,7 @@ void CNullDriver::deleteHardwareBuffer(SHWBufferLink *HWBuffer)
 {\r
        if (!HWBuffer)\r
                return;\r
-       HWBufferMap.remove(HWBuffer->MeshBuffer);\r
+       HWBufferList.erase(HWBuffer->listPosition);\r
        delete HWBuffer;\r
 }\r
 \r
@@ -1844,17 +1464,19 @@ void CNullDriver::deleteHardwareBuffer(SHWBufferLink *HWBuffer)
 //! Remove hardware buffer\r
 void CNullDriver::removeHardwareBuffer(const scene::IMeshBuffer* mb)\r
 {\r
-       core::map<const scene::IMeshBuffer*,SHWBufferLink*>::Node* node = HWBufferMap.find(mb);\r
-       if (node)\r
-               deleteHardwareBuffer(node->getValue());\r
+       if (!mb)\r
+               return;\r
+       SHWBufferLink *HWBuffer = reinterpret_cast<SHWBufferLink*>(mb->getHWBuffer());\r
+       if (HWBuffer)\r
+               deleteHardwareBuffer(HWBuffer);\r
 }\r
 \r
 \r
 //! Remove all hardware buffers\r
 void CNullDriver::removeAllHardwareBuffers()\r
 {\r
-       while (HWBufferMap.size())\r
-               deleteHardwareBuffer(HWBufferMap.getRoot()->getValue());\r
+       while (!HWBufferList.empty())\r
+               deleteHardwareBuffer(HWBufferList.front());\r
 }\r
 \r
 \r
@@ -2095,10 +1717,10 @@ s32 CNullDriver::addMaterialRenderer(IMaterialRenderer* renderer, const char* na
 \r
 \r
 //! Sets the name of a material renderer.\r
-void CNullDriver::setMaterialRendererName(s32 idx, const char* name)\r
+void CNullDriver::setMaterialRendererName(u32 idx, const char* name)\r
 {\r
-       if (idx < s32(sizeof(sBuiltInMaterialTypeNames) / sizeof(char*))-1 ||\r
-               idx >= (s32)MaterialRenderers.size())\r
+       if (idx < (sizeof(sBuiltInMaterialTypeNames) / sizeof(char*))-1 ||\r
+               idx >= MaterialRenderers.size())\r
                return;\r
 \r
        MaterialRenderers[idx].Name = name;\r
@@ -2114,193 +1736,6 @@ void CNullDriver::swapMaterialRenderers(u32 idx1, u32 idx2, bool swapNames)
        }\r
 }\r
 \r
-//! Creates material attributes list from a material, usable for serialization and more.\r
-io::IAttributes* CNullDriver::createAttributesFromMaterial(const video::SMaterial& material,\r
-       io::SAttributeReadWriteOptions* options)\r
-{\r
-       io::CAttributes* attr = new io::CAttributes(this);\r
-\r
-       attr->addEnum("Type", material.MaterialType, sBuiltInMaterialTypeNames);\r
-\r
-       attr->addColor("Ambient", material.AmbientColor);\r
-       attr->addColor("Diffuse", material.DiffuseColor);\r
-       attr->addColor("Emissive", material.EmissiveColor);\r
-       attr->addColor("Specular", material.SpecularColor);\r
-\r
-       attr->addFloat("Shininess", material.Shininess);\r
-       attr->addFloat("Param1", material.MaterialTypeParam);\r
-       attr->addFloat("Param2", material.MaterialTypeParam2);\r
-       attr->addFloat("Thickness", material.Thickness);\r
-\r
-       core::stringc prefix="Texture";\r
-       u32 i;\r
-       for (i=0; i<MATERIAL_MAX_TEXTURES; ++i)\r
-       {\r
-               video::ITexture* texture = material.getTexture(i);\r
-               if (options && (options->Flags&io::EARWF_USE_RELATIVE_PATHS) && options->Filename && texture)\r
-               {\r
-                       io::path path = FileSystem->getRelativeFilename(\r
-                               FileSystem->getAbsolutePath(material.getTexture(i)->getName()), options->Filename);\r
-                       attr->addTexture((prefix+core::stringc(i+1)).c_str(), material.getTexture(i), path);\r
-               }\r
-               else\r
-               {\r
-                       attr->addTexture((prefix+core::stringc(i+1)).c_str(), texture);\r
-               }\r
-       }\r
-\r
-       attr->addBool("Wireframe", material.Wireframe);\r
-       attr->addBool("PointCloud", material.PointCloud);\r
-       attr->addBool("GouraudShading", material.GouraudShading);\r
-       attr->addBool("Lighting", material.Lighting);\r
-       attr->addEnum("ZWriteEnable", (irr::s32)material.ZWriteEnable, video::ZWriteNames);\r
-       attr->addInt("ZBuffer", material.ZBuffer);\r
-       attr->addBool("BackfaceCulling", material.BackfaceCulling);\r
-       attr->addBool("FrontfaceCulling", material.FrontfaceCulling);\r
-       attr->addBool("FogEnable", material.FogEnable);\r
-       attr->addBool("NormalizeNormals", material.NormalizeNormals);\r
-       attr->addBool("UseMipMaps", material.UseMipMaps);\r
-       attr->addInt("AntiAliasing", material.AntiAliasing);\r
-       attr->addInt("ColorMask", material.ColorMask);\r
-       attr->addInt("ColorMaterial", material.ColorMaterial);\r
-       attr->addInt("BlendOperation", material.BlendOperation);\r
-       attr->addFloat("BlendFactor", material.BlendFactor);\r
-       attr->addInt("PolygonOffsetFactor", material.PolygonOffsetFactor);\r
-       attr->addEnum("PolygonOffsetDirection", material.PolygonOffsetDirection, video::PolygonOffsetDirectionNames);\r
-       attr->addFloat("PolygonOffsetDepthBias", material.PolygonOffsetDepthBias);\r
-       attr->addFloat("PolygonOffsetSlopeScale", material.PolygonOffsetSlopeScale);\r
-\r
-       // TODO: Would be nice to have a flag that only serializes rest of texture data when a texture pointer exists.\r
-       prefix = "BilinearFilter";\r
-       for (i=0; i<MATERIAL_MAX_TEXTURES; ++i)\r
-               attr->addBool((prefix+core::stringc(i+1)).c_str(), material.TextureLayer[i].BilinearFilter);\r
-       prefix = "TrilinearFilter";\r
-       for (i=0; i<MATERIAL_MAX_TEXTURES; ++i)\r
-               attr->addBool((prefix+core::stringc(i+1)).c_str(), material.TextureLayer[i].TrilinearFilter);\r
-       prefix = "AnisotropicFilter";\r
-       for (i=0; i<MATERIAL_MAX_TEXTURES; ++i)\r
-               attr->addInt((prefix+core::stringc(i+1)).c_str(), material.TextureLayer[i].AnisotropicFilter);\r
-       prefix="TextureWrapU";\r
-       for (i=0; i<MATERIAL_MAX_TEXTURES; ++i)\r
-               attr->addEnum((prefix+core::stringc(i+1)).c_str(), material.TextureLayer[i].TextureWrapU, aTextureClampNames);\r
-       prefix="TextureWrapV";\r
-       for (i=0; i<MATERIAL_MAX_TEXTURES; ++i)\r
-               attr->addEnum((prefix+core::stringc(i+1)).c_str(), material.TextureLayer[i].TextureWrapV, aTextureClampNames);\r
-       prefix="TextureWrapW";\r
-       for (i=0; i<MATERIAL_MAX_TEXTURES; ++i)\r
-               attr->addEnum((prefix+core::stringc(i+1)).c_str(), material.TextureLayer[i].TextureWrapW, aTextureClampNames);\r
-       prefix="LODBias";\r
-       for (i=0; i<MATERIAL_MAX_TEXTURES; ++i)\r
-               attr->addInt((prefix+core::stringc(i+1)).c_str(), material.TextureLayer[i].LODBias);\r
-\r
-       return attr;\r
-}\r
-\r
-\r
-//! Fills an SMaterial structure from attributes.\r
-void CNullDriver::fillMaterialStructureFromAttributes(video::SMaterial& outMaterial, io::IAttributes* attr)\r
-{\r
-       outMaterial.MaterialType = video::EMT_SOLID;\r
-\r
-       core::stringc name = attr->getAttributeAsString("Type");\r
-\r
-       u32 i;\r
-\r
-       for ( i=0; i < MaterialRenderers.size(); ++i)\r
-               if ( name == MaterialRenderers[i].Name )\r
-               {\r
-                       outMaterial.MaterialType = (video::E_MATERIAL_TYPE)i;\r
-                       break;\r
-               }\r
-\r
-       outMaterial.AmbientColor = attr->getAttributeAsColor("Ambient", outMaterial.AmbientColor);\r
-       outMaterial.DiffuseColor = attr->getAttributeAsColor("Diffuse", outMaterial.DiffuseColor);\r
-       outMaterial.EmissiveColor = attr->getAttributeAsColor("Emissive", outMaterial.EmissiveColor);\r
-       outMaterial.SpecularColor = attr->getAttributeAsColor("Specular", outMaterial.SpecularColor);\r
-\r
-       outMaterial.Shininess = attr->getAttributeAsFloat("Shininess", outMaterial.Shininess);\r
-       outMaterial.MaterialTypeParam = attr->getAttributeAsFloat("Param1", outMaterial.MaterialTypeParam);\r
-       outMaterial.MaterialTypeParam2 = attr->getAttributeAsFloat("Param2", outMaterial.MaterialTypeParam2);\r
-       outMaterial.Thickness = attr->getAttributeAsFloat("Thickness", outMaterial.Thickness);\r
-\r
-       core::stringc prefix="Texture";\r
-       for (i=0; i<MATERIAL_MAX_TEXTURES; ++i)\r
-               outMaterial.setTexture(i, attr->getAttributeAsTexture((prefix+core::stringc(i+1)).c_str()));\r
-\r
-       outMaterial.Wireframe = attr->getAttributeAsBool("Wireframe", outMaterial.Wireframe);\r
-       outMaterial.PointCloud = attr->getAttributeAsBool("PointCloud", outMaterial.PointCloud);\r
-       outMaterial.GouraudShading = attr->getAttributeAsBool("GouraudShading", outMaterial.GouraudShading);\r
-       outMaterial.Lighting = attr->getAttributeAsBool("Lighting", outMaterial.Lighting);\r
-\r
-       io::E_ATTRIBUTE_TYPE attType = attr->getAttributeType("ZWriteEnable");\r
-       if (attType == io::EAT_BOOL )   // Before Irrlicht 1.9\r
-               outMaterial.ZWriteEnable = attr->getAttributeAsBool("ZWriteEnable", outMaterial.ZWriteEnable != video::EZW_OFF ) ? video::EZW_AUTO : video::EZW_OFF;\r
-       else if (attType == io::EAT_ENUM )\r
-               outMaterial.ZWriteEnable = (video::E_ZWRITE)attr->getAttributeAsEnumeration("ZWriteEnable", video::ZWriteNames, outMaterial.ZWriteEnable);\r
-\r
-       outMaterial.ZBuffer = (u8)attr->getAttributeAsInt("ZBuffer", outMaterial.ZBuffer);\r
-       outMaterial.BackfaceCulling = attr->getAttributeAsBool("BackfaceCulling", outMaterial.BackfaceCulling);\r
-       outMaterial.FrontfaceCulling = attr->getAttributeAsBool("FrontfaceCulling", outMaterial.FrontfaceCulling);\r
-       outMaterial.FogEnable = attr->getAttributeAsBool("FogEnable", outMaterial.FogEnable);\r
-       outMaterial.NormalizeNormals = attr->getAttributeAsBool("NormalizeNormals", outMaterial.NormalizeNormals);\r
-       outMaterial.UseMipMaps = attr->getAttributeAsBool("UseMipMaps", outMaterial.UseMipMaps);\r
-\r
-       outMaterial.AntiAliasing = attr->getAttributeAsInt("AntiAliasing", outMaterial.AntiAliasing);\r
-       outMaterial.ColorMask = attr->getAttributeAsInt("ColorMask", outMaterial.ColorMask);\r
-       outMaterial.ColorMaterial = attr->getAttributeAsInt("ColorMaterial", outMaterial.ColorMaterial);\r
-       outMaterial.BlendOperation = (video::E_BLEND_OPERATION)attr->getAttributeAsInt("BlendOperation", outMaterial.BlendOperation);\r
-       outMaterial.BlendFactor = attr->getAttributeAsFloat("BlendFactor", outMaterial.BlendFactor);\r
-       outMaterial.PolygonOffsetFactor = attr->getAttributeAsInt("PolygonOffsetFactor", outMaterial.PolygonOffsetFactor);\r
-       outMaterial.PolygonOffsetDirection = (video::E_POLYGON_OFFSET)attr->getAttributeAsEnumeration("PolygonOffsetDirection", video::PolygonOffsetDirectionNames, outMaterial.PolygonOffsetDirection);\r
-       outMaterial.PolygonOffsetDepthBias = attr->getAttributeAsFloat("PolygonOffsetDepthBias", outMaterial.PolygonOffsetDepthBias);\r
-       outMaterial.PolygonOffsetSlopeScale = attr->getAttributeAsFloat("PolygonOffsetSlopeScale", outMaterial.PolygonOffsetSlopeScale);\r
-\r
-       prefix = "BilinearFilter";\r
-       if (attr->existsAttribute(prefix.c_str())) // legacy\r
-               outMaterial.setFlag(EMF_BILINEAR_FILTER, attr->getAttributeAsBool(prefix.c_str()));\r
-       else\r
-               for (i=0; i<MATERIAL_MAX_TEXTURES; ++i)\r
-                       outMaterial.TextureLayer[i].BilinearFilter = attr->getAttributeAsBool((prefix+core::stringc(i+1)).c_str(), outMaterial.TextureLayer[i].BilinearFilter);\r
-\r
-       prefix = "TrilinearFilter";\r
-       if (attr->existsAttribute(prefix.c_str())) // legacy\r
-               outMaterial.setFlag(EMF_TRILINEAR_FILTER, attr->getAttributeAsBool(prefix.c_str()));\r
-       else\r
-               for (i=0; i<MATERIAL_MAX_TEXTURES; ++i)\r
-                       outMaterial.TextureLayer[i].TrilinearFilter = attr->getAttributeAsBool((prefix+core::stringc(i+1)).c_str(), outMaterial.TextureLayer[i].TrilinearFilter);\r
-\r
-       prefix = "AnisotropicFilter";\r
-       if (attr->existsAttribute(prefix.c_str())) // legacy\r
-               outMaterial.setFlag(EMF_ANISOTROPIC_FILTER, attr->getAttributeAsBool(prefix.c_str()));\r
-       else\r
-               for (i=0; i<MATERIAL_MAX_TEXTURES; ++i)\r
-                       outMaterial.TextureLayer[i].AnisotropicFilter = attr->getAttributeAsInt((prefix+core::stringc(i+1)).c_str(), outMaterial.TextureLayer[i].AnisotropicFilter);\r
-\r
-       prefix = "TextureWrap";\r
-       if (attr->existsAttribute(prefix.c_str())) // legacy\r
-       {\r
-               for (i=0; i<MATERIAL_MAX_TEXTURES; ++i)\r
-               {\r
-                       outMaterial.TextureLayer[i].TextureWrapU = (E_TEXTURE_CLAMP)attr->getAttributeAsEnumeration((prefix+core::stringc(i+1)).c_str(), aTextureClampNames);\r
-                       outMaterial.TextureLayer[i].TextureWrapV = outMaterial.TextureLayer[i].TextureWrapU;\r
-                       outMaterial.TextureLayer[i].TextureWrapW = outMaterial.TextureLayer[i].TextureWrapW;\r
-               }\r
-       }\r
-       else\r
-       {\r
-               for (i=0; i<MATERIAL_MAX_TEXTURES; ++i)\r
-               {\r
-                       outMaterial.TextureLayer[i].TextureWrapU = (E_TEXTURE_CLAMP)attr->getAttributeAsEnumeration((prefix+"U"+core::stringc(i+1)).c_str(), aTextureClampNames, outMaterial.TextureLayer[i].TextureWrapU);\r
-                       outMaterial.TextureLayer[i].TextureWrapV = (E_TEXTURE_CLAMP)attr->getAttributeAsEnumeration((prefix+"V"+core::stringc(i+1)).c_str(), aTextureClampNames, outMaterial.TextureLayer[i].TextureWrapV);\r
-                       outMaterial.TextureLayer[i].TextureWrapW = (E_TEXTURE_CLAMP)attr->getAttributeAsEnumeration((prefix+"W"+core::stringc(i+1)).c_str(), aTextureClampNames, outMaterial.TextureLayer[i].TextureWrapW);\r
-               }\r
-       }\r
-\r
-       prefix="LODBias";\r
-       for (i=0; i<MATERIAL_MAX_TEXTURES; ++i)\r
-               outMaterial.TextureLayer[i].LODBias = attr->getAttributeAsInt((prefix+core::stringc(i+1)).c_str(), outMaterial.TextureLayer[i].LODBias);\r
-}\r
-\r
 \r
 //! Returns driver and operating system specific data about the IVideoDriver.\r
 const SExposedVideoData& CNullDriver::getExposedVideoData()\r
@@ -2763,9 +2198,9 @@ bool CNullDriver::needsTransparentRenderPass(const irr::video::SMaterial& materi
        //      zwrite disabled and getWriteZBuffer calls this function.\r
 \r
        video::IMaterialRenderer* rnd = getMaterialRenderer(material.MaterialType);\r
-       // TODO: I suspect IMaterialRenderer::isTransparent also often could use SMaterial as parameter \r
+       // TODO: I suspect IMaterialRenderer::isTransparent also often could use SMaterial as parameter\r
        //       We could for example then get rid of IsTransparent function in SMaterial and move that to the software material renderer.\r
-       if (rnd && rnd->isTransparent())        \r
+       if (rnd && rnd->isTransparent())\r
                return true;\r
 \r
        return false;\r