#include "CNullDriver.h"
#include "os.h"
#include "CImage.h"
#include "CAttributes.h"
#include "IReadFile.h"
#include "IWriteFile.h"
#include "IImageLoader.h"
#include "IImageWriter.h"
#include "IMaterialRenderer.h"
#include "IAnimatedMeshSceneNode.h"
#include "CMeshManipulator.h"
#include "CColorConverter.h"
namespace irr
{
namespace video
{
IImageLoader* createImageLoaderBMP();
IImageLoader* createImageLoaderJPG();
IImageLoader* createImageLoaderTGA();
IImageLoader* createImageLoaderPSD();
IImageLoader* createImageLoaderDDS();
IImageLoader* createImageLoaderPCX();
IImageLoader* createImageLoaderPNG();
IImageLoader* createImageLoaderWAL();
IImageLoader* createImageLoaderHalfLife();
IImageLoader* createImageLoaderLMP();
IImageLoader* createImageLoaderPPM();
IImageLoader* createImageLoaderRGB();
IImageWriter* createImageWriterBMP();
IImageWriter* createImageWriterJPG();
IImageWriter* createImageWriterTGA();
IImageWriter* createImageWriterPSD();
IImageWriter* createImageWriterPCX();
IImageWriter* createImageWriterPNG();
IImageWriter* createImageWriterPPM();
CNullDriver::CNullDriver(io::IFileSystem* io, const core::dimension2d<u32>& screenSize)
: FileSystem(io), MeshManipulator(0), ViewPort(0,0,0,0), ScreenSize(screenSize),
PrimitivesDrawn(0), MinVertexCountForVBO(32), TextureCreationFlags(0),
OverrideMaterial2DEnabled(false), AllowZWriteOnTransparent(false)
{
#ifdef _DEBUG
setDebugName("CNullDriver");
#endif
DriverAttributes = new io::CAttributes();
DriverAttributes->addInt("MaxTextures", _IRR_MATERIAL_MAX_TEXTURES_);
DriverAttributes->addInt("MaxSupportedTextures", _IRR_MATERIAL_MAX_TEXTURES_);
DriverAttributes->addInt("MaxLights", getMaximalDynamicLightAmount());
DriverAttributes->addInt("MaxAnisotropy", 1);
DriverAttributes->addInt("MaxMultipleRenderTargets", 1);
DriverAttributes->addInt("MaxIndices", -1);
DriverAttributes->addInt("MaxTextureSize", -1);
DriverAttributes->addInt("Version", 1);
setFog();
setTextureCreationFlag(ETCF_ALWAYS_32_BIT, true);
setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, true);
ViewPort = core::rect<s32>(core::position2d<s32>(0,0), core::dimension2di(screenSize));
MeshManipulator = new scene::CMeshManipulator();
if (FileSystem)
FileSystem->grab();
#ifdef _IRR_COMPILE_WITH_HALFLIFE_LOADER_
SurfaceLoader.push_back(video::createImageLoaderHalfLife());
#endif
#ifdef _IRR_COMPILE_WITH_WAL_LOADER_
SurfaceLoader.push_back(video::createImageLoaderWAL());
#endif
#ifdef _IRR_COMPILE_WITH_LMP_LOADER_
SurfaceLoader.push_back(video::createImageLoaderLMP());
#endif
#ifdef _IRR_COMPILE_WITH_PPM_LOADER_
SurfaceLoader.push_back(video::createImageLoaderPPM());
#endif
#ifdef _IRR_COMPILE_WITH_RGB_LOADER_
SurfaceLoader.push_back(video::createImageLoaderRGB());
#endif
#ifdef _IRR_COMPILE_WITH_PSD_LOADER_
SurfaceLoader.push_back(video::createImageLoaderPSD());
#endif
#ifdef _IRR_COMPILE_WITH_DDS_LOADER_
SurfaceLoader.push_back(video::createImageLoaderDDS());
#endif
#ifdef _IRR_COMPILE_WITH_PCX_LOADER_
SurfaceLoader.push_back(video::createImageLoaderPCX());
#endif
#ifdef _IRR_COMPILE_WITH_TGA_LOADER_
SurfaceLoader.push_back(video::createImageLoaderTGA());
#endif
#ifdef _IRR_COMPILE_WITH_PNG_LOADER_
SurfaceLoader.push_back(video::createImageLoaderPNG());
#endif
#ifdef _IRR_COMPILE_WITH_JPG_LOADER_
SurfaceLoader.push_back(video::createImageLoaderJPG());
#endif
#ifdef _IRR_COMPILE_WITH_BMP_LOADER_
SurfaceLoader.push_back(video::createImageLoaderBMP());
#endif
#ifdef _IRR_COMPILE_WITH_PPM_WRITER_
SurfaceWriter.push_back(video::createImageWriterPPM());
#endif
#ifdef _IRR_COMPILE_WITH_PCX_WRITER_
SurfaceWriter.push_back(video::createImageWriterPCX());
#endif
#ifdef _IRR_COMPILE_WITH_PSD_WRITER_
SurfaceWriter.push_back(video::createImageWriterPSD());
#endif
#ifdef _IRR_COMPILE_WITH_TGA_WRITER_
SurfaceWriter.push_back(video::createImageWriterTGA());
#endif
#ifdef _IRR_COMPILE_WITH_JPG_WRITER_
SurfaceWriter.push_back(video::createImageWriterJPG());
#endif
#ifdef _IRR_COMPILE_WITH_PNG_WRITER_
SurfaceWriter.push_back(video::createImageWriterPNG());
#endif
#ifdef _IRR_COMPILE_WITH_BMP_WRITER_
SurfaceWriter.push_back(video::createImageWriterBMP());
#endif
memset(&ExposedData, 0, sizeof(ExposedData));
for (u32 i=0; i<video::EVDF_COUNT; ++i)
FeatureEnabled[i]=true;
InitMaterial2D.AntiAliasing=video::EAAM_OFF;
InitMaterial2D.Lighting=false;
InitMaterial2D.ZWriteEnable=false;
InitMaterial2D.ZBuffer=video::ECFN_NEVER;
InitMaterial2D.UseMipMaps=false;
for (u32 i=0; i<video::MATERIAL_MAX_TEXTURES; ++i)
{
InitMaterial2D.TextureLayer[i].BilinearFilter=false;
InitMaterial2D.TextureLayer[i].TextureWrapU=video::ETC_REPEAT;
InitMaterial2D.TextureLayer[i].TextureWrapV=video::ETC_REPEAT;
}
OverrideMaterial2D=InitMaterial2D;
}
CNullDriver::~CNullDriver()
{
if (DriverAttributes)
DriverAttributes->drop();
if (FileSystem)
FileSystem->drop();
if (MeshManipulator)
MeshManipulator->drop();
deleteAllTextures();
u32 i;
for (i=0; i<SurfaceLoader.size(); ++i)
SurfaceLoader[i]->drop();
for (i=0; i<SurfaceWriter.size(); ++i)
SurfaceWriter[i]->drop();
deleteMaterialRenders();
removeAllHardwareBuffers();
}
void CNullDriver::addExternalImageLoader(IImageLoader* loader)
{
if (!loader)
return;
loader->grab();
SurfaceLoader.push_back(loader);
}
void CNullDriver::addExternalImageWriter(IImageWriter* writer)
{
if (!writer)
return;
writer->grab();
SurfaceWriter.push_back(writer);
}
u32 CNullDriver::getImageLoaderCount() const
{
return SurfaceLoader.size();
}
IImageLoader* CNullDriver::getImageLoader(u32 n)
{
if (n < SurfaceLoader.size())
return SurfaceLoader[n];
return 0;
}
u32 CNullDriver::getImageWriterCount() const
{
return SurfaceWriter.size();
}
IImageWriter* CNullDriver::getImageWriter(u32 n)
{
if (n < SurfaceWriter.size())
return SurfaceWriter[n];
return 0;
}
void CNullDriver::deleteAllTextures()
{
setMaterial(SMaterial());
for (u32 i=0; i<Textures.size(); ++i)
Textures[i].Surface->drop();
Textures.clear();
}
bool CNullDriver::beginScene(bool backBuffer, bool zBuffer, SColor color,
const SExposedVideoData& videoData, core::rect<s32>* sourceRect)
{
core::clearFPUException();
PrimitivesDrawn = 0;
return true;
}
bool CNullDriver::endScene()
{
FPSCounter.registerFrame(os::Timer::getRealTime(), PrimitivesDrawn);
updateAllHardwareBuffers();
updateAllOcclusionQueries();
return true;
}
void CNullDriver::disableFeature(E_VIDEO_DRIVER_FEATURE feature, bool flag)
{
FeatureEnabled[feature]=!flag;
}
bool CNullDriver::queryFeature(E_VIDEO_DRIVER_FEATURE feature) const
{
return false;
}
const io::IAttributes& CNullDriver::getDriverAttributes() const
{
return *DriverAttributes;
}
void CNullDriver::setTransform(E_TRANSFORMATION_STATE state, const core::matrix4& mat)
{
}
const core::matrix4& CNullDriver::getTransform(E_TRANSFORMATION_STATE state) const
{
return TransformationMatrix;
}
void CNullDriver::setMaterial(const SMaterial& material)
{
}
void CNullDriver::removeTexture(ITexture* texture)
{
if (!texture)
return;
for (u32 i=0; i<Textures.size(); ++i)
{
if (Textures[i].Surface == texture)
{
texture->drop();
Textures.erase(i);
}
}
}
void CNullDriver::removeAllTextures()
{
setMaterial ( SMaterial() );
deleteAllTextures();
}
ITexture* CNullDriver::getTextureByIndex(u32 i)
{
if ( i < Textures.size() )
return Textures[i].Surface;
return 0;
}
u32 CNullDriver::getTextureCount() const
{
return Textures.size();
}
void CNullDriver::renameTexture(ITexture* texture, const io::path& newName)
{
io::SNamedPath& name = const_cast<io::SNamedPath&>(texture->getName());
name.setPath(newName);
Textures.sort();
}
ITexture* CNullDriver::getTexture(const io::path& filename)
{
const io::path absolutePath = FileSystem->getAbsolutePath(filename);
ITexture* texture = findTexture(absolutePath);
if (texture)
return texture;
texture = findTexture(filename);
if (texture)
return texture;
io::IReadFile* file = FileSystem->createAndOpenFile(absolutePath);
if (!file)
{
file = FileSystem->createAndOpenFile(filename);
}
if (file)
{
texture = findTexture(file->getFileName());
if (texture)
{
file->drop();
return texture;
}
texture = loadTextureFromFile(file);
file->drop();
if (texture)
{
addTexture(texture);
texture->drop();
}
else
os::Printer::log("Could not load texture", filename, ELL_ERROR);
return texture;
}
else
{
os::Printer::log("Could not open file of texture", filename, ELL_WARNING);
return 0;
}
}
ITexture* CNullDriver::getTexture(io::IReadFile* file)
{
ITexture* texture = 0;
if (file)
{
texture = findTexture(file->getFileName());
if (texture)
return texture;
texture = loadTextureFromFile(file);
if (texture)
{
addTexture(texture);
texture->drop();
}
if (!texture)
os::Printer::log("Could not load texture", file->getFileName(), ELL_WARNING);
}
return texture;
}
video::ITexture* CNullDriver::loadTextureFromFile(io::IReadFile* file, const io::path& hashName )
{
ITexture* texture = 0;
IImage* image = createImageFromFile(file);
if (image)
{
texture = createDeviceDependentTexture(image, hashName.size() ? hashName : file->getFileName() );
os::Printer::log("Loaded texture", file->getFileName());
image->drop();
}
return texture;
}
void CNullDriver::addTexture(video::ITexture* texture)
{
if (texture)
{
SSurface s;
s.Surface = texture;
texture->grab();
Textures.push_back(s);
Textures.sort();
}
}
video::ITexture* CNullDriver::findTexture(const io::path& filename)
{
SSurface s;
SDummyTexture dummy(filename);
s.Surface = &dummy;
s32 index = Textures.binary_search(s);
if (index != -1)
return Textures[index].Surface;
return 0;
}
ITexture* CNullDriver::addTexture(const io::path& name, IImage* image, void* mipmapData)
{
if ( 0 == name.size() || !image)
return 0;
ITexture* t = createDeviceDependentTexture(image, name, mipmapData);
if (t)
{
addTexture(t);
t->drop();
}
return t;
}
ITexture* CNullDriver::addTexture(const core::dimension2d<u32>& size,
const io::path& name, ECOLOR_FORMAT format)
{
if(IImage::isRenderTargetOnlyFormat(format))
{
os::Printer::log("Could not create ITexture, format only supported for render target textures.", ELL_WARNING);
return 0;
}
if ( 0 == name.size () )
return 0;
IImage* image = new CImage(format, size);
ITexture* t = createDeviceDependentTexture(image, name);
image->drop();
addTexture(t);
if (t)
t->drop();
return t;
}
ITexture* CNullDriver::createDeviceDependentTexture(IImage* surface, const io::path& name, void* mipmapData)
{
return new SDummyTexture(name);
}
bool CNullDriver::setRenderTarget(video::E_RENDER_TARGET target, bool clearTarget,
bool clearZBuffer, SColor color)
{
if (ERT_FRAME_BUFFER==target)
return setRenderTarget(0,clearTarget, clearZBuffer, color);
else
return false;
}
bool CNullDriver::setRenderTarget(video::ITexture* texture, bool clearBackBuffer,
bool clearZBuffer, SColor color)
{
return false;
}
bool CNullDriver::setRenderTarget(const core::array<video::IRenderTarget>& texture,
bool clearBackBuffer, bool clearZBuffer, SColor color)
{
return false;
}
void CNullDriver::setViewPort(const core::rect<s32>& area)
{
}
const core::rect<s32>& CNullDriver::getViewPort() const
{
return ViewPort;
}
void CNullDriver::drawVertexPrimitiveList(const void* vertices, u32 vertexCount, const void* indexList, u32 primitiveCount, E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType)
{
if ((iType==EIT_16BIT) && (vertexCount>65536))
os::Printer::log("Too many vertices for 16bit index type, render artifacts may occur.");
PrimitivesDrawn += primitiveCount;
}
void CNullDriver::draw2DVertexPrimitiveList(const void* vertices, u32 vertexCount, const void* indexList, u32 primitiveCount, E_VERTEX_TYPE vType, scene::E_PRIMITIVE_TYPE pType, E_INDEX_TYPE iType)
{
if ((iType==EIT_16BIT) && (vertexCount>65536))
os::Printer::log("Too many vertices for 16bit index type, render artifacts may occur.");
PrimitivesDrawn += primitiveCount;
}
void CNullDriver::draw3DLine(const core::vector3df& start,
const core::vector3df& end, SColor color)
{
}
void CNullDriver::draw3DTriangle(const core::triangle3df& triangle, SColor color)
{
S3DVertex vertices[3];
vertices[0].Pos=triangle.pointA;
vertices[0].Color=color;
vertices[0].Normal=triangle.getNormal().normalize();
vertices[0].TCoords.set(0.f,0.f);
vertices[1].Pos=triangle.pointB;
vertices[1].Color=color;
vertices[1].Normal=vertices[0].Normal;
vertices[1].TCoords.set(0.5f,1.f);
vertices[2].Pos=triangle.pointC;
vertices[2].Color=color;
vertices[2].Normal=vertices[0].Normal;
vertices[2].TCoords.set(1.f,0.f);
const u16 indexList[] = {0,1,2};
drawVertexPrimitiveList(vertices, 3, indexList, 1, EVT_STANDARD, scene::EPT_TRIANGLES, EIT_16BIT);
}
void CNullDriver::draw3DBox(const core::aabbox3d<f32>& box, SColor color)
{
core::vector3df edges[8];
box.getEdges(edges);
draw3DLine(edges[5], edges[1], color);
draw3DLine(edges[1], edges[3], color);
draw3DLine(edges[3], edges[7], color);
draw3DLine(edges[7], edges[5], color);
draw3DLine(edges[0], edges[2], color);
draw3DLine(edges[2], edges[6], color);
draw3DLine(edges[6], edges[4], color);
draw3DLine(edges[4], edges[0], color);
draw3DLine(edges[1], edges[0], color);
draw3DLine(edges[3], edges[2], color);
draw3DLine(edges[7], edges[6], color);
draw3DLine(edges[5], edges[4], color);
}
void CNullDriver::draw2DImage(const video::ITexture* texture, const core::position2d<s32>& destPos)
{
if (!texture)
return;
draw2DImage(texture,destPos, core::rect<s32>(core::position2d<s32>(0,0),
core::dimension2di(texture->getOriginalSize())));
}
void CNullDriver::draw2DImageBatch(const video::ITexture* texture,
const core::position2d<s32>& pos,
const core::array<core::rect<s32> >& sourceRects,
const core::array<s32>& indices,
s32 kerningWidth,
const core::rect<s32>* clipRect, SColor color,
bool useAlphaChannelOfTexture)
{
core::position2d<s32> target(pos);
for (u32 i=0; i<indices.size(); ++i)
{
draw2DImage(texture, target, sourceRects[indices[i]],
clipRect, color, useAlphaChannelOfTexture);
target.X += sourceRects[indices[i]].getWidth();
target.X += kerningWidth;
}
}
void CNullDriver::draw2DImageBatch(const video::ITexture* texture,
const core::array<core::position2d<s32> >& positions,
const core::array<core::rect<s32> >& sourceRects,
const core::rect<s32>* clipRect,
SColor color,
bool useAlphaChannelOfTexture)
{
const irr::u32 drawCount = core::min_<u32>(positions.size(), sourceRects.size());
for (u32 i=0; i<drawCount; ++i)
{
draw2DImage(texture, positions[i], sourceRects[i],
clipRect, color, useAlphaChannelOfTexture);
}
}
void CNullDriver::draw2DImage(const video::ITexture* texture, const core::rect<s32>& destRect,
const core::rect<s32>& sourceRect, const core::rect<s32>* clipRect,
const video::SColor* const colors, bool useAlphaChannelOfTexture)
{
draw2DImage(texture, core::position2d<s32>(destRect.UpperLeftCorner),
sourceRect, clipRect, colors?colors[0]:video::SColor(0xffffffff),
useAlphaChannelOfTexture);
}
void CNullDriver::draw2DImage(const video::ITexture* texture, const core::position2d<s32>& destPos,
const core::rect<s32>& sourceRect,
const core::rect<s32>* clipRect, SColor color,
bool useAlphaChannelOfTexture)
{
}
void CNullDriver::draw2DRectangleOutline(const core::recti& pos, SColor color)
{
draw2DLine(pos.UpperLeftCorner, core::position2di(pos.LowerRightCorner.X, pos.UpperLeftCorner.Y), color);
draw2DLine(core::position2di(pos.LowerRightCorner.X, pos.UpperLeftCorner.Y), pos.LowerRightCorner, color);
draw2DLine(pos.LowerRightCorner, core::position2di(pos.UpperLeftCorner.X, pos.LowerRightCorner.Y), color);
draw2DLine(core::position2di(pos.UpperLeftCorner.X, pos.LowerRightCorner.Y), pos.UpperLeftCorner, color);
}
void CNullDriver::draw2DRectangle(SColor color, const core::rect<s32>& pos, const core::rect<s32>* clip)
{
draw2DRectangle(pos, color, color, color, color, clip);
}
void CNullDriver::draw2DRectangle(const core::rect<s32>& pos,
SColor colorLeftUp, SColor colorRightUp, SColor colorLeftDown, SColor colorRightDown,
const core::rect<s32>* clip)
{
}
void CNullDriver::draw2DLine(const core::position2d<s32>& start,
const core::position2d<s32>& end, SColor color)
{
}
void CNullDriver::drawPixel(u32 x, u32 y, const SColor & color)
{
}
void CNullDriver::draw2DPolygon(core::position2d<s32> center,
f32 radius, video::SColor color, s32 count)
{
if (count < 2)
return;
core::position2d<s32> first;
core::position2d<s32> a,b;
for (s32 j=0; j<count; ++j)
{
b = a;
f32 p = j / (f32)count * (core::PI*2);
a = center + core::position2d<s32>((s32)(sin(p)*radius), (s32)(cos(p)*radius));
if (j==0)
first = a;
else
draw2DLine(a, b, color);
}
draw2DLine(a, first, color);
}
ECOLOR_FORMAT CNullDriver::getColorFormat() const
{
return ECF_R5G6B5;
}
const core::dimension2d<u32>& CNullDriver::getScreenSize() const
{
return ScreenSize;
}
const core::dimension2d<u32>& CNullDriver::getCurrentRenderTargetSize() const
{
return ScreenSize;
}
s32 CNullDriver::getFPS() const
{
return FPSCounter.getFPS();
}
u32 CNullDriver::getPrimitiveCountDrawn( u32 param ) const
{
return (0 == param) ? FPSCounter.getPrimitive() : (1 == param) ? FPSCounter.getPrimitiveAverage() : FPSCounter.getPrimitiveTotal();
}
void CNullDriver::setAmbientLight(const SColorf& color)
{
}
const wchar_t* CNullDriver::getName() const
{
return L"Irrlicht NullDevice";
}
void CNullDriver::drawStencilShadowVolume(const core::vector3df* triangles, s32 count, bool zfail)
{
}
void CNullDriver::drawStencilShadow(bool clearStencilBuffer,
video::SColor leftUpEdge, video::SColor rightUpEdge,
video::SColor leftDownEdge, video::SColor rightDownEdge)
{
}
void CNullDriver::deleteAllDynamicLights()
{
Lights.set_used(0);
}
s32 CNullDriver::addDynamicLight(const SLight& light)
{
Lights.push_back(light);
return Lights.size() - 1;
}
void CNullDriver::turnLightOn(s32 lightIndex, bool turnOn)
{
}
u32 CNullDriver::getMaximalDynamicLightAmount() const
{
return 0;
}
u32 CNullDriver::getDynamicLightCount() const
{
return Lights.size();
}
const SLight& CNullDriver::getDynamicLight(u32 idx) const
{
if ( idx < Lights.size() )
return Lights[idx];
else
return *((SLight*)0);
}
void CNullDriver::makeColorKeyTexture(video::ITexture* texture,
video::SColor color,
bool zeroTexels) const
{
if (!texture)
return;
if (texture->getColorFormat() != ECF_A1R5G5B5 &&
texture->getColorFormat() != ECF_A8R8G8B8 )
{
os::Printer::log("Error: Unsupported texture color format for making color key channel.", ELL_ERROR);
return;
}
if (texture->getColorFormat() == ECF_A1R5G5B5)
{
u16 *p = (u16*)texture->lock();
if (!p)
{
os::Printer::log("Could not lock texture for making color key channel.", ELL_ERROR);
return;
}
const core::dimension2d<u32> dim = texture->getSize();
const u32 pitch = texture->getPitch() / 2;
const u16 refZeroAlpha = (0x7fff & color.toA1R5G5B5());
const u32 pixels = pitch * dim.Height;
for (u32 pixel = 0; pixel < pixels; ++ pixel)
{
if(((*p) & 0x7fff) == refZeroAlpha)
{
if(zeroTexels)
(*p) = 0;
else
(*p) = refZeroAlpha;
}
++p;
}
texture->unlock();
}
else
{
u32 *p = (u32*)texture->lock();
if (!p)
{
os::Printer::log("Could not lock texture for making color key channel.", ELL_ERROR);
return;
}
core::dimension2d<u32> dim = texture->getSize();
u32 pitch = texture->getPitch() / 4;
const u32 refZeroAlpha = 0x00ffffff & color.color;
const u32 pixels = pitch * dim.Height;
for (u32 pixel = 0; pixel < pixels; ++ pixel)
{
if(((*p) & 0x00ffffff) == refZeroAlpha)
{
if(zeroTexels)
(*p) = 0;
else
(*p) = refZeroAlpha;
}
++p;
}
texture->unlock();
}
}
void CNullDriver::makeColorKeyTexture(video::ITexture* texture,
core::position2d<s32> colorKeyPixelPos,
bool zeroTexels) const
{
if (!texture)
return;
if (texture->getColorFormat() != ECF_A1R5G5B5 &&
texture->getColorFormat() != ECF_A8R8G8B8 )
{
os::Printer::log("Error: Unsupported texture color format for making color key channel.", ELL_ERROR);
return;
}
SColor colorKey;
if (texture->getColorFormat() == ECF_A1R5G5B5)
{
u16 *p = (u16*)texture->lock(ETLM_READ_ONLY);
if (!p)
{
os::Printer::log("Could not lock texture for making color key channel.", ELL_ERROR);
return;
}
u32 pitch = texture->getPitch() / 2;
const u16 key16Bit = 0x7fff & p[colorKeyPixelPos.Y*pitch + colorKeyPixelPos.X];
colorKey = video::A1R5G5B5toA8R8G8B8(key16Bit);
}
else
{
u32 *p = (u32*)texture->lock(ETLM_READ_ONLY);
if (!p)
{
os::Printer::log("Could not lock texture for making color key channel.", ELL_ERROR);
return;
}
u32 pitch = texture->getPitch() / 4;
colorKey = 0x00ffffff & p[colorKeyPixelPos.Y*pitch + colorKeyPixelPos.X];
}
texture->unlock();
makeColorKeyTexture(texture, colorKey, zeroTexels);
}
void CNullDriver::makeNormalMapTexture(video::ITexture* texture, f32 amplitude) const
{
if (!texture)
return;
if (texture->getColorFormat() != ECF_A1R5G5B5 &&
texture->getColorFormat() != ECF_A8R8G8B8 )
{
os::Printer::log("Error: Unsupported texture color format for making normal map.", ELL_ERROR);
return;
}
core::dimension2d<u32> dim = texture->getSize();
amplitude = amplitude / 255.0f;
f32 vh = dim.Height / (f32)dim.Width;
f32 hh = dim.Width / (f32)dim.Height;
if (texture->getColorFormat() == ECF_A8R8G8B8)
{
s32 *p = (s32*)texture->lock();
if (!p)
{
os::Printer::log("Could not lock texture for making normal map.", ELL_ERROR);
return;
}
u32 pitch = texture->getPitch() / 4;
s32* in = new s32[dim.Height * pitch];
memcpy(in, p, dim.Height * pitch * 4);
for (s32 x=0; x < s32(pitch); ++x)
for (s32 y=0; y < s32(dim.Height); ++y)
{
core::vector3df h1((x-1)*hh, nml32(x-1, y, pitch, dim.Height, in)*amplitude, y*vh);
core::vector3df h2((x+1)*hh, nml32(x+1, y, pitch, dim.Height, in)*amplitude, y*vh);
core::vector3df v1(x*hh, nml32(x, y+1, pitch, dim.Height, in)*amplitude, (y-1)*vh);
core::vector3df v2(x*hh, nml32(x, y-1, pitch, dim.Height, in)*amplitude, (y+1)*vh);
core::vector3df v = v1-v2;
core::vector3df h = h1-h2;
core::vector3df n = v.crossProduct(h);
n.normalize();
n *= 0.5f;
n += core::vector3df(0.5f,0.5f,0.5f);
n *= 255.0f;
s32 height = (s32)nml32(x, y, pitch, dim.Height, in);
p[y*pitch + x] = video::SColor(
height,
(s32)n.X, (s32)n.Z, (s32)n.Y).color;
}
delete [] in;
texture->unlock();
}
else
{
s16 *p = (s16*)texture->lock();
if (!p)
{
os::Printer::log("Could not lock texture for making normal map.", ELL_ERROR);
return;
}
u32 pitch = texture->getPitch() / 2;
s16* in = new s16[dim.Height * pitch];
memcpy(in, p, dim.Height * pitch * 2);
for (s32 x=0; x < s32(pitch); ++x)
for (s32 y=0; y < s32(dim.Height); ++y)
{
core::vector3df h1((x-1)*hh, nml16(x-1, y, pitch, dim.Height, in)*amplitude, y*vh);
core::vector3df h2((x+1)*hh, nml16(x+1, y, pitch, dim.Height, in)*amplitude, y*vh);
core::vector3df v1(x*hh, nml16(x, y-1, pitch, dim.Height, in)*amplitude, (y-1)*vh);
core::vector3df v2(x*hh, nml16(x, y+1, pitch, dim.Height, in)*amplitude, (y+1)*vh);
core::vector3df v = v1-v2;
core::vector3df h = h1-h2;
core::vector3df n = v.crossProduct(h);
n.normalize();
n *= 0.5f;
n += core::vector3df(0.5f,0.5f,0.5f);
n *= 255.0f;
p[y*pitch + x] = video::RGBA16((u32)n.X, (u32)n.Z, (u32)n.Y);
}
delete [] in;
texture->unlock();
}
texture->regenerateMipMapLevels();
}
u32 CNullDriver::getMaximalPrimitiveCount() const
{
return 0xFFFFFFFF;
}
bool CNullDriver::checkPrimitiveCount(u32 prmCount) const
{
const u32 m = getMaximalPrimitiveCount();
if (prmCount > m)
{
char tmp[1024];
sprintf(tmp,"Could not draw triangles, too many primitives(%u), maxium is %u.", prmCount, m);
os::Printer::log(tmp, ELL_ERROR);
return false;
}
return true;
}
void CNullDriver::setTextureCreationFlag(E_TEXTURE_CREATION_FLAG flag, bool enabled)
{
if (enabled && ((flag == ETCF_ALWAYS_16_BIT) || (flag == ETCF_ALWAYS_32_BIT)
|| (flag == ETCF_OPTIMIZED_FOR_QUALITY) || (flag == ETCF_OPTIMIZED_FOR_SPEED)))
{
setTextureCreationFlag(ETCF_ALWAYS_16_BIT, false);
setTextureCreationFlag(ETCF_ALWAYS_32_BIT, false);
setTextureCreationFlag(ETCF_OPTIMIZED_FOR_QUALITY, false);
setTextureCreationFlag(ETCF_OPTIMIZED_FOR_SPEED, false);
}
TextureCreationFlags = (TextureCreationFlags & (~flag)) |
((((u32)!enabled)-1) & flag);
}
bool CNullDriver::getTextureCreationFlag(E_TEXTURE_CREATION_FLAG flag) const
{
return (TextureCreationFlags & flag)!=0;
}
IImage* CNullDriver::createImageFromFile(const io::path& filename)
{
if (!filename.size())
return 0;
IImage* image = 0;
io::IReadFile* file = FileSystem->createAndOpenFile(filename);
if (file)
{
image = createImageFromFile(file);
file->drop();
}
else
os::Printer::log("Could not open file of image", filename, ELL_WARNING);
return image;
}
IImage* CNullDriver::createImageFromFile(io::IReadFile* file)
{
if (!file)
return 0;
IImage* image = 0;
s32 i;
for (i=SurfaceLoader.size()-1; i>=0; --i)
{
if (SurfaceLoader[i]->isALoadableFileExtension(file->getFileName()))
{
file->seek(0);
image = SurfaceLoader[i]->loadImage(file);
if (image)
return image;
}
}
for (i=SurfaceLoader.size()-1; i>=0; --i)
{
file->seek(0);
if (SurfaceLoader[i]->isALoadableFileFormat(file))
{
file->seek(0);
image = SurfaceLoader[i]->loadImage(file);
if (image)
return image;
}
}
return 0;
}
bool CNullDriver::writeImageToFile(IImage* image, const io::path& filename,u32 param)
{
io::IWriteFile* file = FileSystem->createAndWriteFile(filename);
if(!file)
return false;
bool result = writeImageToFile(image, file, param);
file->drop();
return result;
}
bool CNullDriver::writeImageToFile(IImage* image, io::IWriteFile * file, u32 param)
{
if(!file)
return false;
for (s32 i=SurfaceWriter.size()-1; i>=0; --i)
{
if (SurfaceWriter[i]->isAWriteableFileExtension(file->getFileName()))
{
bool written = SurfaceWriter[i]->writeImage(file, image, param);
if (written)
return true;
}
}
return false;
}
IImage* CNullDriver::createImageFromData(ECOLOR_FORMAT format,
const core::dimension2d<u32>& size,
void *data, bool ownForeignMemory,
bool deleteMemory)
{
if(IImage::isRenderTargetOnlyFormat(format))
{
os::Printer::log("Could not create IImage, format only supported for render target textures.", ELL_WARNING);
return 0;
}
return new CImage(format, size, data, ownForeignMemory, deleteMemory);
}
IImage* CNullDriver::createImage(ECOLOR_FORMAT format, const core::dimension2d<u32>& size)
{
if(IImage::isRenderTargetOnlyFormat(format))
{
os::Printer::log("Could not create IImage, format only supported for render target textures.", ELL_WARNING);
return 0;
}
return new CImage(format, size);
}
IImage* CNullDriver::createImage(ECOLOR_FORMAT format, IImage *imageToCopy)
{
os::Printer::log("Deprecated method, please create an empty image instead and use copyTo().", ELL_WARNING);
if(IImage::isRenderTargetOnlyFormat(format))
{
os::Printer::log("Could not create IImage, format only supported for render target textures.", ELL_WARNING);
return 0;
}
CImage* tmp = new CImage(format, imageToCopy->getDimension());
imageToCopy->copyTo(tmp);
return tmp;
}
IImage* CNullDriver::createImage(IImage* imageToCopy, const core::position2d<s32>& pos, const core::dimension2d<u32>& size)
{
os::Printer::log("Deprecated method, please create an empty image instead and use copyTo().", ELL_WARNING);
CImage* tmp = new CImage(imageToCopy->getColorFormat(), imageToCopy->getDimension());
imageToCopy->copyTo(tmp, core::position2di(0,0), core::recti(pos,size));
return tmp;
}
IImage* CNullDriver::createImage(ITexture* texture, const core::position2d<s32>& pos, const core::dimension2d<u32>& size)
{
if ((pos==core::position2di(0,0)) && (size == texture->getSize()))
{
IImage* image = new CImage(texture->getColorFormat(), size, texture->lock(ETLM_READ_ONLY), false);
texture->unlock();
return image;
}
else
{
const core::vector2d<u32> leftUpper(core::clamp(static_cast<u32>(pos.X), 0u, texture->getSize().Width),
core::clamp(static_cast<u32>(pos.Y), 0u, texture->getSize().Height));
const core::rect<u32> clamped(leftUpper,
core::dimension2du(core::clamp(static_cast<u32>(size.Width), 0u, texture->getSize().Width),
core::clamp(static_cast<u32>(size.Height), 0u, texture->getSize().Height)));
if (!clamped.isValid())
return 0;
u8* src = static_cast<u8*>(texture->lock(ETLM_READ_ONLY));
if (!src)
return 0;
IImage* image = new CImage(texture->getColorFormat(), clamped.getSize());
u8* dst = static_cast<u8*>(image->lock());
src += clamped.UpperLeftCorner.Y * texture->getPitch() + image->getBytesPerPixel() * clamped.UpperLeftCorner.X;
for (u32 i=0; i<clamped.getHeight(); ++i)
{
video::CColorConverter::convert_viaFormat(src, texture->getColorFormat(), clamped.getWidth(), dst, image->getColorFormat());
src += texture->getPitch();
dst += image->getPitch();
}
image->unlock();
texture->unlock();
return image;
}
}
void CNullDriver::setFog(SColor color, E_FOG_TYPE fogType, f32 start, f32 end,
f32 density, bool pixelFog, bool rangeFog)
{
FogColor = color;
FogType = fogType;
FogStart = start;
FogEnd = end;
FogDensity = density;
PixelFog = pixelFog;
RangeFog = rangeFog;
}
void CNullDriver::getFog(SColor& color, E_FOG_TYPE& fogType, f32& start, f32& end,
f32& density, bool& pixelFog, bool& rangeFog)
{
color = FogColor;
fogType = FogType;
start = FogStart;
end = FogEnd;
density = FogDensity;
pixelFog = PixelFog;
rangeFog = RangeFog;
}
void CNullDriver::drawMeshBuffer(const scene::IMeshBuffer* mb)
{
if (!mb)
return;
SHWBufferLink *HWBuffer=getBufferLink(mb);
if (HWBuffer)
drawHardwareBuffer(HWBuffer);
else
drawVertexPrimitiveList(mb->getVertices(), mb->getVertexCount(), mb->getIndices(), mb->getIndexCount()/3, mb->getVertexType(), scene::EPT_TRIANGLES, mb->getIndexType());
}
CNullDriver::SHWBufferLink *CNullDriver::getBufferLink(const scene::IMeshBuffer* mb)
{
if (!mb || !isHardwareBufferRecommend(mb))
return 0;
core::map< const scene::IMeshBuffer*,SHWBufferLink* >::Node* node = HWBufferMap.find(mb);
if (node)
return node->getValue();
return createHardwareBuffer(mb);
}
void CNullDriver::updateAllHardwareBuffers()
{
core::map<const scene::IMeshBuffer*,SHWBufferLink*>::ParentFirstIterator Iterator=HWBufferMap.getParentFirstIterator();
for (;!Iterator.atEnd();Iterator++)
{
SHWBufferLink *Link=Iterator.getNode()->getValue();
Link->LastUsed++;
if (Link->LastUsed>20000)
{
deleteHardwareBuffer(Link);
Iterator = HWBufferMap.getParentFirstIterator();
}
}
}
void CNullDriver::deleteHardwareBuffer(SHWBufferLink *HWBuffer)
{
if (!HWBuffer)
return;
HWBufferMap.remove(HWBuffer->MeshBuffer);
delete HWBuffer;
}
void CNullDriver::removeHardwareBuffer(const scene::IMeshBuffer* mb)
{
core::map<const scene::IMeshBuffer*,SHWBufferLink*>::Node* node = HWBufferMap.find(mb);
if (node)
deleteHardwareBuffer(node->getValue());
}
void CNullDriver::removeAllHardwareBuffers()
{
while (HWBufferMap.size())
deleteHardwareBuffer(HWBufferMap.getRoot()->getValue());
}
bool CNullDriver::isHardwareBufferRecommend(const scene::IMeshBuffer* mb)
{
if (!mb || (mb->getHardwareMappingHint_Index()==scene::EHM_NEVER && mb->getHardwareMappingHint_Vertex()==scene::EHM_NEVER))
return false;
if (mb->getVertexCount()<MinVertexCountForVBO)
return false;
return true;
}
void CNullDriver::createOcclusionQuery(scene::ISceneNode* node, const scene::IMesh* mesh)
{
if (!node)
return;
if (!mesh)
{
if ((node->getType() != scene::ESNT_MESH) && (node->getType() != scene::ESNT_ANIMATED_MESH))
return;
else if (node->getType() == scene::ESNT_MESH)
mesh = static_cast<scene::IMeshSceneNode*>(node)->getMesh();
else
mesh = static_cast<scene::IAnimatedMeshSceneNode*>(node)->getMesh()->getMesh(0);
if (!mesh)
return;
}
s32 index = OcclusionQueries.linear_search(SOccQuery(node));
if (index != -1)
{
if (OcclusionQueries[index].Mesh != mesh)
{
OcclusionQueries[index].Mesh->drop();
OcclusionQueries[index].Mesh = mesh;
mesh->grab();
}
}
else
{
OcclusionQueries.push_back(SOccQuery(node, mesh));
node->setAutomaticCulling(node->getAutomaticCulling() | scene::EAC_OCC_QUERY);
}
}
void CNullDriver::removeOcclusionQuery(scene::ISceneNode* node)
{
s32 index = OcclusionQueries.linear_search(SOccQuery(node));
if (index != -1)
{
node->setAutomaticCulling(node->getAutomaticCulling() & ~scene::EAC_OCC_QUERY);
OcclusionQueries.erase(index);
}
}
void CNullDriver::removeAllOcclusionQueries()
{
for (s32 i=OcclusionQueries.size()-1; i>=0; --i)
{
removeOcclusionQuery(OcclusionQueries[i].Node);
}
}
void CNullDriver::runOcclusionQuery(scene::ISceneNode* node, bool visible)
{
if(!node)
return;
s32 index = OcclusionQueries.linear_search(SOccQuery(node));
if (index==-1)
return;
OcclusionQueries[index].Run=0;
if (!visible)
{
SMaterial mat;
mat.Lighting=false;
mat.AntiAliasing=0;
mat.ColorMask=ECP_NONE;
mat.GouraudShading=false;
mat.ZWriteEnable=false;
setMaterial(mat);
}
setTransform(video::ETS_WORLD, node->getAbsoluteTransformation());
const scene::IMesh* mesh = OcclusionQueries[index].Mesh;
for (u32 i=0; i<mesh->getMeshBufferCount(); ++i)
{
if (visible)
setMaterial(mesh->getMeshBuffer(i)->getMaterial());
drawMeshBuffer(mesh->getMeshBuffer(i));
}
}
void CNullDriver::runAllOcclusionQueries(bool visible)
{
for (u32 i=0; i<OcclusionQueries.size(); ++i)
runOcclusionQuery(OcclusionQueries[i].Node, visible);
}
void CNullDriver::updateOcclusionQuery(scene::ISceneNode* node, bool block)
{
}
void CNullDriver::updateAllOcclusionQueries(bool block)
{
for (u32 i=0; i<OcclusionQueries.size(); ++i)
{
if (OcclusionQueries[i].Run==u32(~0))
continue;
updateOcclusionQuery(OcclusionQueries[i].Node, block);
++OcclusionQueries[i].Run;
if (OcclusionQueries[i].Run>1000)
removeOcclusionQuery(OcclusionQueries[i].Node);
}
}
u32 CNullDriver::getOcclusionQueryResult(scene::ISceneNode* node) const
{
return ~0;
}
void CNullDriver::OnResize(const core::dimension2d<u32>& size)
{
if (ViewPort.getWidth() == (s32)ScreenSize.Width &&
ViewPort.getHeight() == (s32)ScreenSize.Height)
ViewPort = core::rect<s32>(core::position2d<s32>(0,0),
core::dimension2di(size));
ScreenSize = size;
}
s32 CNullDriver::addAndDropMaterialRenderer(IMaterialRenderer* m)
{
s32 i = addMaterialRenderer(m);
if (m)
m->drop();
return i;
}
s32 CNullDriver::addMaterialRenderer(IMaterialRenderer* renderer, const char* name)
{
if (!renderer)
return -1;
SMaterialRenderer r;
r.Renderer = renderer;
r.Name = name;
if (name == 0 && (MaterialRenderers.size() < (sizeof(sBuiltInMaterialTypeNames) / sizeof(char*))-1 ))
{
r.Name = sBuiltInMaterialTypeNames[MaterialRenderers.size()];
}
MaterialRenderers.push_back(r);
renderer->grab();
return MaterialRenderers.size()-1;
}
void CNullDriver::setMaterialRendererName(s32 idx, const char* name)
{
if (idx < s32(sizeof(sBuiltInMaterialTypeNames) / sizeof(char*))-1 ||
idx >= (s32)MaterialRenderers.size())
return;
MaterialRenderers[idx].Name = name;
}
io::IAttributes* CNullDriver::createAttributesFromMaterial(const video::SMaterial& material)
{
io::CAttributes* attr = new io::CAttributes(this);
attr->addEnum("Type", material.MaterialType, sBuiltInMaterialTypeNames);
attr->addColor("Ambient", material.AmbientColor);
attr->addColor("Diffuse", material.DiffuseColor);
attr->addColor("Emissive", material.EmissiveColor);
attr->addColor("Specular", material.SpecularColor);
attr->addFloat("Shininess", material.Shininess);
attr->addFloat("Param1", material.MaterialTypeParam);
attr->addFloat("Param2", material.MaterialTypeParam2);
core::stringc prefix="Texture";
u32 i;
for (i=0; i<MATERIAL_MAX_TEXTURES; ++i)
attr->addTexture((prefix+core::stringc(i+1)).c_str(), material.getTexture(i));
attr->addBool("Wireframe", material.Wireframe);
attr->addBool("GouraudShading", material.GouraudShading);
attr->addBool("Lighting", material.Lighting);
attr->addBool("ZWriteEnable", material.ZWriteEnable);
attr->addInt("ZBuffer", material.ZBuffer);
attr->addBool("BackfaceCulling", material.BackfaceCulling);
attr->addBool("FrontfaceCulling", material.FrontfaceCulling);
attr->addBool("FogEnable", material.FogEnable);
attr->addBool("NormalizeNormals", material.NormalizeNormals);
attr->addBool("UseMipMaps", material.UseMipMaps);
attr->addInt("AntiAliasing", material.AntiAliasing);
attr->addInt("ColorMask", material.ColorMask);
prefix = "BilinearFilter";
for (i=0; i<MATERIAL_MAX_TEXTURES; ++i)
attr->addBool((prefix+core::stringc(i+1)).c_str(), material.TextureLayer[i].BilinearFilter);
prefix = "TrilinearFilter";
for (i=0; i<MATERIAL_MAX_TEXTURES; ++i)
attr->addBool((prefix+core::stringc(i+1)).c_str(), material.TextureLayer[i].TrilinearFilter);
prefix = "AnisotropicFilter";
for (i=0; i<MATERIAL_MAX_TEXTURES; ++i)
attr->addInt((prefix+core::stringc(i+1)).c_str(), material.TextureLayer[i].AnisotropicFilter);
prefix="TextureWrapU";
for (i=0; i<MATERIAL_MAX_TEXTURES; ++i)
attr->addEnum((prefix+core::stringc(i+1)).c_str(), material.TextureLayer[i].TextureWrapU, aTextureClampNames);
prefix="TextureWrapV";
for (i=0; i<MATERIAL_MAX_TEXTURES; ++i)
attr->addEnum((prefix+core::stringc(i+1)).c_str(), material.TextureLayer[i].TextureWrapV, aTextureClampNames);
prefix="LODBias";
for (i=0; i<MATERIAL_MAX_TEXTURES; ++i)
attr->addInt((prefix+core::stringc(i+1)).c_str(), material.TextureLayer[i].LODBias);
return attr;
}
void CNullDriver::fillMaterialStructureFromAttributes(video::SMaterial& outMaterial, io::IAttributes* attr)
{
outMaterial.MaterialType = video::EMT_SOLID;
core::stringc name = attr->getAttributeAsString("Type");
u32 i;
for ( i=0; i < MaterialRenderers.size(); ++i)
if ( name == MaterialRenderers[i].Name )
{
outMaterial.MaterialType = (video::E_MATERIAL_TYPE)i;
break;
}
outMaterial.AmbientColor = attr->getAttributeAsColor("Ambient");
outMaterial.DiffuseColor = attr->getAttributeAsColor("Diffuse");
outMaterial.EmissiveColor = attr->getAttributeAsColor("Emissive");
outMaterial.SpecularColor = attr->getAttributeAsColor("Specular");
outMaterial.Shininess = attr->getAttributeAsFloat("Shininess");
outMaterial.MaterialTypeParam = attr->getAttributeAsFloat("Param1");
outMaterial.MaterialTypeParam2 = attr->getAttributeAsFloat("Param2");
core::stringc prefix="Texture";
for (i=0; i<MATERIAL_MAX_TEXTURES; ++i)
outMaterial.setTexture(i, attr->getAttributeAsTexture((prefix+core::stringc(i+1)).c_str()));
outMaterial.Wireframe = attr->getAttributeAsBool("Wireframe");
outMaterial.GouraudShading = attr->getAttributeAsBool("GouraudShading");
outMaterial.Lighting = attr->getAttributeAsBool("Lighting");
outMaterial.ZWriteEnable = attr->getAttributeAsBool("ZWriteEnable");
outMaterial.ZBuffer = (u8)attr->getAttributeAsInt("ZBuffer");
outMaterial.BackfaceCulling = attr->getAttributeAsBool("BackfaceCulling");
outMaterial.FrontfaceCulling = attr->getAttributeAsBool("FrontfaceCulling");
outMaterial.FogEnable = attr->getAttributeAsBool("FogEnable");
outMaterial.NormalizeNormals = attr->getAttributeAsBool("NormalizeNormals");
if (attr->existsAttribute("UseMipMaps"))
outMaterial.UseMipMaps = attr->getAttributeAsBool("UseMipMaps");
else
outMaterial.UseMipMaps = true;
outMaterial.AntiAliasing = attr->getAttributeAsInt("AntiAliasing");
if (attr->existsAttribute("ColorMask"))
outMaterial.ColorMask = attr->getAttributeAsInt("ColorMask");
prefix = "BilinearFilter";
if (attr->existsAttribute(prefix.c_str()))
outMaterial.setFlag(EMF_BILINEAR_FILTER, attr->getAttributeAsBool(prefix.c_str()));
else
for (i=0; i<MATERIAL_MAX_TEXTURES; ++i)
outMaterial.TextureLayer[i].BilinearFilter = attr->getAttributeAsBool((prefix+core::stringc(i+1)).c_str());
prefix = "TrilinearFilter";
if (attr->existsAttribute(prefix.c_str()))
outMaterial.setFlag(EMF_TRILINEAR_FILTER, attr->getAttributeAsBool(prefix.c_str()));
else
for (i=0; i<MATERIAL_MAX_TEXTURES; ++i)
outMaterial.TextureLayer[i].TrilinearFilter = attr->getAttributeAsBool((prefix+core::stringc(i+1)).c_str());
prefix = "AnisotropicFilter";
if (attr->existsAttribute(prefix.c_str()))
outMaterial.setFlag(EMF_ANISOTROPIC_FILTER, attr->getAttributeAsBool(prefix.c_str()));
else
for (i=0; i<MATERIAL_MAX_TEXTURES; ++i)
outMaterial.TextureLayer[i].AnisotropicFilter = attr->getAttributeAsInt((prefix+core::stringc(i+1)).c_str());
prefix = "TextureWrap";
if (attr->existsAttribute(prefix.c_str()))
{
for (i=0; i<MATERIAL_MAX_TEXTURES; ++i)
{
outMaterial.TextureLayer[i].TextureWrapU = (E_TEXTURE_CLAMP)attr->getAttributeAsEnumeration((prefix+core::stringc(i+1)).c_str(), aTextureClampNames);
outMaterial.TextureLayer[i].TextureWrapV = outMaterial.TextureLayer[i].TextureWrapU;
}
}
else
{
for (i=0; i<MATERIAL_MAX_TEXTURES; ++i)
{
outMaterial.TextureLayer[i].TextureWrapU = (E_TEXTURE_CLAMP)attr->getAttributeAsEnumeration((prefix+"U"+core::stringc(i+1)).c_str(), aTextureClampNames);
outMaterial.TextureLayer[i].TextureWrapV = (E_TEXTURE_CLAMP)attr->getAttributeAsEnumeration((prefix+"V"+core::stringc(i+1)).c_str(), aTextureClampNames);
}
}
prefix="LODBias";
for (i=0; i<MATERIAL_MAX_TEXTURES; ++i)
outMaterial.TextureLayer[i].LODBias = attr->getAttributeAsInt((prefix+core::stringc(i+1)).c_str());
}
const SExposedVideoData& CNullDriver::getExposedVideoData()
{
return ExposedData;
}
E_DRIVER_TYPE CNullDriver::getDriverType() const
{
return EDT_NULL;
}
void CNullDriver::deleteMaterialRenders()
{
for (u32 i=0; i<MaterialRenderers.size(); ++i)
if (MaterialRenderers[i].Renderer)
MaterialRenderers[i].Renderer->drop();
MaterialRenderers.clear();
}
IMaterialRenderer* CNullDriver::getMaterialRenderer(u32 idx)
{
if ( idx < MaterialRenderers.size() )
return MaterialRenderers[idx].Renderer;
else
return 0;
}
u32 CNullDriver::getMaterialRendererCount() const
{
return MaterialRenderers.size();
}
const char* CNullDriver::getMaterialRendererName(u32 idx) const
{
if ( idx < MaterialRenderers.size() )
return MaterialRenderers[idx].Name.c_str();
return 0;
}
IGPUProgrammingServices* CNullDriver::getGPUProgrammingServices()
{
return this;
}
s32 CNullDriver::addHighLevelShaderMaterial(
const c8* vertexShaderProgram,
const c8* vertexShaderEntryPointName,
E_VERTEX_SHADER_TYPE vsCompileTarget,
const c8* pixelShaderProgram,
const c8* pixelShaderEntryPointName,
E_PIXEL_SHADER_TYPE psCompileTarget,
const c8* geometryShaderProgram,
const c8* geometryShaderEntryPointName,
E_GEOMETRY_SHADER_TYPE gsCompileTarget,
scene::E_PRIMITIVE_TYPE inType, scene::E_PRIMITIVE_TYPE outType,
u32 verticesOut,
IShaderConstantSetCallBack* callback,
E_MATERIAL_TYPE baseMaterial,
s32 userData)
{
os::Printer::log("High level shader materials not available (yet) in this driver, sorry");
return -1;
}
s32 CNullDriver::addHighLevelShaderMaterialFromFiles(
const io::path& vertexShaderProgramFileName,
const c8* vertexShaderEntryPointName,
E_VERTEX_SHADER_TYPE vsCompileTarget,
const io::path& pixelShaderProgramFileName,
const c8* pixelShaderEntryPointName,
E_PIXEL_SHADER_TYPE psCompileTarget,
const io::path& geometryShaderProgramFileName,
const c8* geometryShaderEntryPointName,
E_GEOMETRY_SHADER_TYPE gsCompileTarget,
scene::E_PRIMITIVE_TYPE inType, scene::E_PRIMITIVE_TYPE outType,
u32 verticesOut,
IShaderConstantSetCallBack* callback,
E_MATERIAL_TYPE baseMaterial,
s32 userData)
{
io::IReadFile* vsfile = 0;
io::IReadFile* psfile = 0;
io::IReadFile* gsfile = 0;
if (vertexShaderProgramFileName.size() )
{
vsfile = FileSystem->createAndOpenFile(vertexShaderProgramFileName);
if (!vsfile)
{
os::Printer::log("Could not open vertex shader program file",
vertexShaderProgramFileName, ELL_WARNING);
}
}
if (pixelShaderProgramFileName.size() )
{
psfile = FileSystem->createAndOpenFile(pixelShaderProgramFileName);
if (!psfile)
{
os::Printer::log("Could not open pixel shader program file",
pixelShaderProgramFileName, ELL_WARNING);
}
}
if (geometryShaderProgramFileName.size() )
{
gsfile = FileSystem->createAndOpenFile(geometryShaderProgramFileName);
if (!gsfile)
{
os::Printer::log("Could not open geometry shader program file",
geometryShaderProgramFileName, ELL_WARNING);
}
}
s32 result = addHighLevelShaderMaterialFromFiles(
vsfile, vertexShaderEntryPointName, vsCompileTarget,
psfile, pixelShaderEntryPointName, psCompileTarget,
gsfile, geometryShaderEntryPointName, gsCompileTarget,
inType, outType, verticesOut,
callback, baseMaterial, userData);
if (psfile)
psfile->drop();
if (vsfile)
vsfile->drop();
if (gsfile)
gsfile->drop();
return result;
}
s32 CNullDriver::addHighLevelShaderMaterialFromFiles(
io::IReadFile* vertexShaderProgram,
const c8* vertexShaderEntryPointName,
E_VERTEX_SHADER_TYPE vsCompileTarget,
io::IReadFile* pixelShaderProgram,
const c8* pixelShaderEntryPointName,
E_PIXEL_SHADER_TYPE psCompileTarget,
io::IReadFile* geometryShaderProgram,
const c8* geometryShaderEntryPointName,
E_GEOMETRY_SHADER_TYPE gsCompileTarget,
scene::E_PRIMITIVE_TYPE inType, scene::E_PRIMITIVE_TYPE outType,
u32 verticesOut,
IShaderConstantSetCallBack* callback,
E_MATERIAL_TYPE baseMaterial,
s32 userData)
{
c8* vs = 0;
c8* ps = 0;
c8* gs = 0;
if (vertexShaderProgram)
{
const long size = vertexShaderProgram->getSize();
if (size)
{
vs = new c8[size+1];
vertexShaderProgram->read(vs, size);
vs[size] = 0;
}
}
if (pixelShaderProgram)
{
const long size = pixelShaderProgram->getSize();
if (size)
{
if (pixelShaderProgram==vertexShaderProgram)
pixelShaderProgram->seek(0);
ps = new c8[size+1];
pixelShaderProgram->read(ps, size);
ps[size] = 0;
}
}
if (geometryShaderProgram)
{
const long size = geometryShaderProgram->getSize();
if (size)
{
if ((geometryShaderProgram==vertexShaderProgram) ||
(geometryShaderProgram==pixelShaderProgram))
geometryShaderProgram->seek(0);
gs = new c8[size+1];
geometryShaderProgram->read(gs, size);
gs[size] = 0;
}
}
s32 result = this->addHighLevelShaderMaterial(
vs, vertexShaderEntryPointName, vsCompileTarget,
ps, pixelShaderEntryPointName, psCompileTarget,
gs, geometryShaderEntryPointName, gsCompileTarget,
inType, outType, verticesOut,
callback, baseMaterial, userData);
delete [] vs;
delete [] ps;
delete [] gs;
return result;
}
s32 CNullDriver::addShaderMaterial(const c8* vertexShaderProgram,
const c8* pixelShaderProgram,
IShaderConstantSetCallBack* callback,
E_MATERIAL_TYPE baseMaterial,
s32 userData)
{
os::Printer::log("Shader materials not implemented yet in this driver, sorry.");
return -1;
}
s32 CNullDriver::addShaderMaterialFromFiles(io::IReadFile* vertexShaderProgram,
io::IReadFile* pixelShaderProgram,
IShaderConstantSetCallBack* callback,
E_MATERIAL_TYPE baseMaterial,
s32 userData)
{
c8* vs = 0;
c8* ps = 0;
if (vertexShaderProgram)
{
const long size = vertexShaderProgram->getSize();
if (size)
{
vs = new c8[size+1];
vertexShaderProgram->read(vs, size);
vs[size] = 0;
}
}
if (pixelShaderProgram)
{
const long size = pixelShaderProgram->getSize();
if (size)
{
ps = new c8[size+1];
pixelShaderProgram->read(ps, size);
ps[size] = 0;
}
}
s32 result = addShaderMaterial(vs, ps, callback, baseMaterial, userData);
delete [] vs;
delete [] ps;
return result;
}
s32 CNullDriver::addShaderMaterialFromFiles(const io::path& vertexShaderProgramFileName,
const io::path& pixelShaderProgramFileName,
IShaderConstantSetCallBack* callback,
E_MATERIAL_TYPE baseMaterial,
s32 userData)
{
io::IReadFile* vsfile = 0;
io::IReadFile* psfile = 0;
if (vertexShaderProgramFileName.size())
{
vsfile = FileSystem->createAndOpenFile(vertexShaderProgramFileName);
if (!vsfile)
{
os::Printer::log("Could not open vertex shader program file",
vertexShaderProgramFileName, ELL_WARNING);
return -1;
}
}
if (pixelShaderProgramFileName.size())
{
psfile = FileSystem->createAndOpenFile(pixelShaderProgramFileName);
if (!psfile)
{
os::Printer::log("Could not open pixel shader program file",
pixelShaderProgramFileName, ELL_WARNING);
if (vsfile)
vsfile->drop();
return -1;
}
}
s32 result = addShaderMaterialFromFiles(vsfile, psfile, callback,
baseMaterial, userData);
if (psfile)
psfile->drop();
if (vsfile)
vsfile->drop();
return result;
}
ITexture* CNullDriver::addRenderTargetTexture(const core::dimension2d<u32>& size,
const io::path&name, const ECOLOR_FORMAT format)
{
return 0;
}
void CNullDriver::clearZBuffer()
{
}
scene::IMeshManipulator* CNullDriver::getMeshManipulator()
{
return MeshManipulator;
}
IImage* CNullDriver::createScreenShot()
{
return 0;
}
void CNullDriver::printVersion()
{
core::stringw namePrint = L"Using renderer: ";
namePrint += getName();
os::Printer::log(namePrint.c_str(), ELL_INFORMATION);
}
IVideoDriver* createNullDriver(io::IFileSystem* io, const core::dimension2d<u32>& screenSize)
{
CNullDriver* nullDriver = new CNullDriver(io, screenSize);
for(u32 i=0; sBuiltInMaterialTypeNames[i]; ++i)
{
IMaterialRenderer* imr = new IMaterialRenderer();
nullDriver->addMaterialRenderer(imr);
imr->drop();
}
return nullDriver;
}
bool CNullDriver::setClipPlane(u32 index, const core::plane3df& plane, bool enable)
{
return false;
}
void CNullDriver::enableClipPlane(u32 index, bool enable)
{
}
ITexture* CNullDriver::createRenderTargetTexture(const core::dimension2d<u32>& size,
const c8* name)
{
os::Printer::log("createRenderTargetTexture is deprecated, use addRenderTargetTexture instead");
ITexture* tex = addRenderTargetTexture(size, name);
tex->grab();
return tex;
}
void CNullDriver::setMinHardwareBufferVertexCount(u32 count)
{
MinVertexCountForVBO = count;
}
SOverrideMaterial& CNullDriver::getOverrideMaterial()
{
return OverrideMaterial;
}
SMaterial& CNullDriver::getMaterial2D()
{
return OverrideMaterial2D;
}
void CNullDriver::enableMaterial2D(bool enable)
{
OverrideMaterial2DEnabled=enable;
}
core::dimension2du CNullDriver::getMaxTextureSize() const
{
return core::dimension2du(0x10000,0x10000);
}
void CNullDriver::convertColor(const void* sP, ECOLOR_FORMAT sF, s32 sN,
void* dP, ECOLOR_FORMAT dF) const
{
video::CColorConverter::convert_viaFormat(sP, sF, sN, dP, dF);
}
}
}