Reindentation and small updates.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@793 dfc29bdd-3216-0410-991c-e03cc46cb475
master
hybrid 2007-07-16 23:46:43 +00:00
parent e29ebb3cd7
commit f1ef8d2fc5
4 changed files with 315 additions and 323 deletions

View File

@ -320,6 +320,23 @@ bool CD3D9Texture::createTexture(u32 flags)
} }
D3DFORMAT CD3D9Texture::getD3DFormatFromColorFormat(ECOLOR_FORMAT format) const
{
switch(format)
{
case ECF_A1R5G5B5:
return D3DFMT_A1R5G5B5;
case ECF_R5G6B5:
return D3DFMT_R5G6B5;
case ECF_R8G8B8:
return D3DFMT_R8G8B8;
case ECF_A8R8G8B8:
return D3DFMT_A8R8G8B8;
}
return D3DFMT_UNKNOWN;
}
ECOLOR_FORMAT CD3D9Texture::getColorFormatFromD3DFormat(D3DFORMAT format) ECOLOR_FORMAT CD3D9Texture::getColorFormatFromD3DFormat(D3DFORMAT format)
{ {
switch(format) switch(format)
@ -419,7 +436,6 @@ bool CD3D9Texture::copyTo16BitTexture()
} }
//! destructor //! destructor
CD3D9Texture::~CD3D9Texture() CD3D9Texture::~CD3D9Texture()
{ {

View File

@ -85,20 +85,26 @@ private:
//! copies the image to the texture //! copies the image to the texture
bool copyTexture(); bool copyTexture();
//! convert color formats
ECOLOR_FORMAT getColorFormatFromD3DFormat(D3DFORMAT format);
//! optimized for 16 bit to 16 copy. //! optimized for 16 bit to 16 copy.
bool copyTo16BitTexture(); bool copyTo16BitTexture();
//! copies texture to 32 bit hardware texture //! copies texture to 32 bit hardware texture
bool copyTo32BitTexture(); bool copyTo32BitTexture();
//! Get D3D color format from Irrlicht color format.
D3DFORMAT getD3DFormatFromColorFormat(ECOLOR_FORMAT format) const;
//! Get Irrlicht color format from D3D color format.
ECOLOR_FORMAT getColorFormatFromD3DFormat(D3DFORMAT format);
//! Helper function for mipmap generation.
bool createMipMaps(u32 level=1); bool createMipMaps(u32 level=1);
//! Helper function for mipmap generation.
void copy16BitMipMap(char* src, char* tgt, void copy16BitMipMap(char* src, char* tgt,
s32 width, s32 height, s32 pitchsrc, s32 pitchtgt); s32 width, s32 height, s32 pitchsrc, s32 pitchtgt);
//! Helper function for mipmap generation.
void copy32BitMipMap(char* src, char* tgt, void copy32BitMipMap(char* src, char* tgt,
s32 width, s32 height, s32 pitchsrc, s32 pitchtgt); s32 width, s32 height, s32 pitchsrc, s32 pitchtgt);

View File

@ -99,25 +99,11 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
u32 i; u32 i;
//begin logging with
//fprintf(flog,"DMF Loader version %1.1f log file\nTrying to load: %s\n",DMFloader_vers,file->getFileName());
dmfHeader header; dmfHeader header;
//load header //load header
if (GetDMFHeader(dmfRawFile, header)) if (GetDMFHeader(dmfRawFile, header))
{ {
//print in log file some statistics
/*fprintf(flog,"DeleD Map Detected\nDeleD Map Version:%1.1f\nScene Name:%s\n"
"Ambient Color(r,g,b):%d,%d,%d\nShadow Intensity:%f\n"
"Number of Objects:%u\nNumber of Materials:%u\n"
"Total Vertices: %u\nTotal Faces: %u\n"
"Total Number of Dynamic Lights: %u\n"
"Trying to Load Materials...",
header.dmfVersion,header.dmfName,
header.dmfAmbient.getRed(),header.dmfAmbient.getGreen(),header.dmfAmbient.getBlue(),
header.dmfShadow,header.numObjects,header.numMaterials,
header.numVertices,header.numFaces,header.numLights);*/
//let's set ambient light //let's set ambient light
SceneMgr->setAmbientLight( header.dmfAmbient); SceneMgr->setAmbientLight( header.dmfAmbient);
@ -130,34 +116,10 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
bool use_mat_dirs=false; bool use_mat_dirs=false;
use_mat_dirs=SceneMgr->getParameters()->getAttributeAsBool(DMF_USE_MATERIALS_DIRS); use_mat_dirs=SceneMgr->getParameters()->getAttributeAsBool(DMF_USE_MATERIALS_DIRS);
if ( GetDMFMaterials(dmfRawFile , materiali,header.numMaterials,use_mat_dirs)) GetDMFMaterials(dmfRawFile , materiali,header.numMaterials,use_mat_dirs);
{
//print to log file some stats
/*fprintf(flog,"Materials Loaded\nShowing 1st and last infos:\n"
" -1st Material (id,texname,lmapname):%u,%s,%s\n"
" -Last Material (id,texname,lmapname):%u,%s,%s\n",
materiali[0].materialID,materiali[0].textureName,
materiali[0].lightmapName,materiali[header.numMaterials-1].materialID,
materiali[header.numMaterials-1].textureName,materiali[header.numMaterials-1].lightmapName);*/
}
/*else
fprintf(flog,"Cannot Load Materials.\n");
fprintf(flog,"Trying to load Vertices and Faces...");*/
//let's get vertices and faces //let's get vertices and faces
if(GetDMFVerticesFaces(dmfRawFile, verts,faces)) GetDMFVerticesFaces(dmfRawFile, verts,faces);
{
/* fprintf(flog,"Loaded\nShowing 1st face and last vertex infos:\n"
" -1st Face (1st vertex,vert num,material id): %u,%u,%u\n"
" -Last vertice (position;tex uv;lmap uv): %f,%f,%f;%f,%f;%f,%f\n",
faces[0].firstVert,faces[0].numVerts,faces[0].materialID,
verts[header.numVertices-1].pos[0],verts[header.numVertices-1].pos[1],verts[header.numVertices-1].pos[2],
verts[header.numVertices-1].tc[0],verts[header.numVertices-1].tc[1],
verts[header.numVertices-1].lc[0],verts[header.numVertices-1].lc[1]);*/
}
/*else
fprintf(flog,"Cannot Load Vertices and Faces.\n");*/
//create a meshbuffer for each material, then we'll remove empty ones //create a meshbuffer for each material, then we'll remove empty ones
for (i=0; i<header.numMaterials; i++) for (i=0; i<header.numMaterials; i++)
@ -236,8 +198,7 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
//a particular material in your scene it will be loaded and then destroyed. //a particular material in your scene it will be loaded and then destroyed.
for (i=0; i<header.numMaterials; i++) for (i=0; i<header.numMaterials; i++)
{ {
String path; String path = "";
path = "";
if ( !SceneMgr->getParameters()->existsAttribute(DMF_TEXTURE_PATH) ) if ( !SceneMgr->getParameters()->existsAttribute(DMF_TEXTURE_PATH) )
{ {
//get the right path for textures //get the right path for textures
@ -249,7 +210,7 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
filepath=filepath1; filepath=filepath1;
} }
for (int j=0; j<(int)(filepath.size()-1); j++) for (u32 j=0; j<filepath.size()-1; ++j)
path = path + filepath[j] + String("\\"); path = path + filepath[j] + String("\\");
} }
else else
@ -260,12 +221,12 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
ITexture *tex = 0; ITexture *tex = 0;
ITexture *lig = 0; ITexture *lig = 0;
//currrent buffer to apply material //current buffer to apply material
SMeshBufferLightMap* buffer = (SMeshBufferLightMap*)Mesh->getMeshBuffer(i); SMeshBufferLightMap* buffer = (SMeshBufferLightMap*)Mesh->getMeshBuffer(i);
//Primary texture is normal //Primary texture is normal
if (materiali[i].textureFlag==0) if ((materiali[i].textureFlag==0) || (materiali[i].textureBlend==4))
if(materiali[i].textureBlend==4) Driver->setTextureCreationFlag (ETCF_ALWAYS_32_BIT,true); Driver->setTextureCreationFlag(ETCF_ALWAYS_32_BIT,true);
tex = Driver->getTexture((path+String(materiali[i].textureName)).c_str()); tex = Driver->getTexture((path+String(materiali[i].textureName)).c_str());
//Primary texture is just a colour //Primary texture is just a colour
@ -295,7 +256,8 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
//just for compatibility with older Irrlicht versions //just for compatibility with older Irrlicht versions
//to support transparent materials //to support transparent materials
if(color.getAlpha()!=255 && materiali[i].textureBlend==4) Driver->setTextureCreationFlag (ETCF_ALWAYS_32_BIT,true); if (color.getAlpha()!=255 && materiali[i].textureBlend==4)
Driver->setTextureCreationFlag(ETCF_ALWAYS_32_BIT,true);
IImage *immagine=Driver->createImageFromData(ECF_A8R8G8B8, IImage *immagine=Driver->createImageFromData(ECF_A8R8G8B8,
core::dimension2d<s32>(8,8),buf); core::dimension2d<s32>(8,8),buf);
@ -303,7 +265,8 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
tex = Driver->addTexture("", immagine); tex = Driver->addTexture("", immagine);
//to support transparent materials //to support transparent materials
if(color.getAlpha()!=255 && materiali[i].textureBlend==4){ if(color.getAlpha()!=255 && materiali[i].textureBlend==4)
{
buffer->Material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL; buffer->Material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
buffer->Material.MaterialTypeParam =(((f32) (color.getAlpha()-1))/255.0f); buffer->Material.MaterialTypeParam =(((f32) (color.getAlpha()-1))/255.0f);
} }
@ -317,12 +280,12 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
{ {
lig = 0; lig = 0;
buffer->Material.MaterialType = video::EMT_SOLID; buffer->Material.MaterialType = video::EMT_SOLID;
f32 mult = 100.0f - header.dmfShadow; const f32 mult = 100.0f - header.dmfShadow;
mult /= 100.0f; buffer->Material.AmbientColor=header.dmfAmbient.getInterpolated(SColor(255,0,0,0),mult/100.f);
buffer->Material.AmbientColor=header.dmfAmbient.getInterpolated ( SColor(255,0,0,0),mult);
} }
if(materiali[i].textureBlend==4) { if(materiali[i].textureBlend==4)
{
buffer->Material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL; buffer->Material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
buffer->Material.MaterialTypeParam =SceneMgr->getParameters()->getAttributeAsFloat(DMF_ALPHA_CHANNEL_REF); buffer->Material.MaterialTypeParam =SceneMgr->getParameters()->getAttributeAsFloat(DMF_ALPHA_CHANNEL_REF);
} }
@ -336,8 +299,6 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
if (lig && header.dmfVersion<1.1) if (lig && header.dmfVersion<1.1)
ligsize=lig->getSize(); ligsize=lig->getSize();
// fprintf(flog,"%s real size w:%d h:%d\n",materiali[i].textureName,texsize.Width,texsize.Height);
//if texture is present mirror vertically owing to DeleD rapresentation //if texture is present mirror vertically owing to DeleD rapresentation
if (tex && header.dmfVersion<1.1) if (tex && header.dmfVersion<1.1)
{ {
@ -356,8 +317,6 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
p[y*texsize.Width + x] = p[(texsize.Height-y-1)*texsize.Width + x]; p[y*texsize.Width + x] = p[(texsize.Height-y-1)*texsize.Width + x];
p[(texsize.Height-y-1)*texsize.Width + x]=tmp; p[(texsize.Height-y-1)*texsize.Width + x]=tmp;
} }
//fprintf(flog," Color Format: ECF_A1R5G5B5\n" );
} }
else else
if (format == video::ECF_A8R8G8B8) if (format == video::ECF_A8R8G8B8)
@ -371,7 +330,6 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
p[y*texsize.Width + x] = p[(texsize.Height-y-1)*texsize.Width + x]; p[y*texsize.Width + x] = p[(texsize.Height-y-1)*texsize.Width + x];
p[(texsize.Height-y-1)*texsize.Width + x]=tmp; p[(texsize.Height-y-1)*texsize.Width + x]=tmp;
} }
//fprintf(flog," Color Format: ECF_A8R8G8B8\n" );
} }
} }
} }
@ -394,29 +352,28 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
s16* p = (s16*)pp; s16* p = (s16*)pp;
s16 tmp=0; s16 tmp=0;
for (s32 x=0; x<ligsize.Width; x++) for (s32 x=0; x<ligsize.Width; x++)
{
for (s32 y=0; y<ligsize.Height/2; y++) for (s32 y=0; y<ligsize.Height/2; y++)
{ {
tmp=p[y*ligsize.Width + x]; tmp=p[y*ligsize.Width + x];
p[y*ligsize.Width + x] = p[(ligsize.Height-y-1)*ligsize.Width + x]; p[y*ligsize.Width + x] = p[(ligsize.Height-y-1)*ligsize.Width + x];
p[(ligsize.Height-y-1)*ligsize.Width + x]=tmp; p[(ligsize.Height-y-1)*ligsize.Width + x]=tmp;
} }
//fprintf(flog," Color Format: ECF_A1R5G5B5\n" );
} }
else }
if (format == video::ECF_A8R8G8B8) else if (format == video::ECF_A8R8G8B8)
{ {
s32* p = (s32*)pp; s32* p = (s32*)pp;
s32 tmp=0; s32 tmp=0;
for (s32 x=0; x<ligsize.Width; x++) for (s32 x=0; x<ligsize.Width; x++)
{
for (s32 y=0; y<ligsize.Height/2; y++) for (s32 y=0; y<ligsize.Height/2; y++)
{ {
tmp=p[y*ligsize.Width + x]; tmp=p[y*ligsize.Width + x];
p[y*ligsize.Width + x] = p[(ligsize.Height-y-1)*ligsize.Width + x]; p[y*ligsize.Width + x] = p[(ligsize.Height-y-1)*ligsize.Width + x];
p[(ligsize.Height-y-1)*ligsize.Width + x]=tmp; p[(ligsize.Height-y-1)*ligsize.Width + x]=tmp;
} }
}
//fprintf(flog," Color Format: ECF_A8R8G8B8\n" );
} }
} }
} }
@ -435,11 +392,6 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
delete faces; delete faces;
delete materiali; delete materiali;
} }
//else
// fprintf(flog,"Cannot load %s, please check it's generated with DeleD 0.91+.");
//closing log file
//fclose(flog);
// delete all buffers without geometry in it. // delete all buffers without geometry in it.
i = 0; i = 0;
@ -459,7 +411,6 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
} }
} }
// create bounding box // create bounding box
for (i = 0; i < Mesh->MeshBuffers.size(); i++) for (i = 0; i < Mesh->MeshBuffers.size(); i++)
{ {
@ -467,7 +418,6 @@ IAnimatedMesh* CDMFLoader::createMesh(io::IReadFile* file)
} }
Mesh->recalculateBoundingBox(); Mesh->recalculateBoundingBox();
// Set up an animated mesh to hold the mesh // Set up an animated mesh to hold the mesh
SAnimatedMesh* AMesh = new SAnimatedMesh(); SAnimatedMesh* AMesh = new SAnimatedMesh();
AMesh->Type = EAMT_UNKNOWN; AMesh->Type = EAMT_UNKNOWN;
@ -490,3 +440,4 @@ bool CDMFLoader::isALoadableFileExtension(const c8* filename)
} // end namespace scene } // end namespace scene
} // end namespace irr } // end namespace irr

View File

@ -944,7 +944,7 @@ CImage::CImage(ECOLOR_FORMAT format, const core::dimension2d<s32>& size, void* d
{ {
Data = 0; Data = 0;
initData(); initData();
memcpy(Data, data, Size.Height * Size.Width * BytesPerPixel); memcpy(Data, data, Size.Height * Pitch);
} }
} }
@ -1281,25 +1281,44 @@ void CImage::copyToScaling(void* target, s32 width, s32 height, ECOLOR_FORMAT fo
if (0==pitch) if (0==pitch)
pitch = width*bpp; pitch = width*bpp;
if (Format==format && Size.Width==width && Size.Height==height && pitch==width*bpp) if (Format==format && Size.Width==width && Size.Height==height)
{
if (pitch==Pitch)
{ {
memcpy(target, Data, height*pitch); memcpy(target, Data, height*pitch);
return; return;
} }
else
{
u8* tgtpos = (u8*) target;
u8* dstpos = (u8*) Data;
const u32 bwidth = width*bpp;
for (s32 y=0; y<height; ++y)
{
memcpy(target, Data, height*pitch);
memset(tgtpos+width, 0, pitch-bwidth);
tgtpos += pitch;
dstpos += Pitch;
}
return;
}
}
const f32 sourceXStep = (f32)Size.Width / (f32)width; const f32 sourceXStep = (f32)Size.Width / (f32)width;
const f32 sourceYStep = (f32)Size.Height / (f32)height; const f32 sourceYStep = (f32)Size.Height / (f32)height;
f32 sx,sy; s32 yval=0, syval=0;
sy = 0.0f; f32 sy = 0.0f;
for (s32 y=0; y<height; ++y) for (s32 y=0; y<height; ++y)
{ {
sx = 0.0f; f32 sx = 0.0f;
for (s32 x=0; x<width; ++x) for (s32 x=0; x<width; ++x)
{ {
CColorConverter::convert_viaFormat(((u8*)Data)+(((s32)sy)*Size.Width + (s32)sx)*BytesPerPixel, Format, 1, ((u8*)target)+(y*pitch + x*bpp), format); CColorConverter::convert_viaFormat(((u8*)Data)+ syval + ((s32)sx)*BytesPerPixel, Format, 1, ((u8*)target)+ yval + (x*bpp), format);
sx+=sourceXStep; sx+=sourceXStep;
} }
sy+=sourceYStep; sy+=sourceYStep;
syval=((s32)sy)*Pitch;
yval+=pitch;
} }
} }