📄 ogrepaginglandscapetexturemanager.cpp
字号:
/***************************************************************************
OgrePagingLandScapeData2DManager.cpp - description
-------------------
begin : Fri Apr 16 2004
copyright : (C) 2003 by Jose A. Milan
email : spoke2@supercable.es
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation; either version 2 of the *
* License, or (at your option) any later version. *
* *
***************************************************************************/
#include "OgreRoot.h"
#include "OgreRenderSystem.h"
#include "OgreGpuProgramManager.h"
#include "OgreException.h"
#include "OgreVector3.h"
#include "OgreColourValue.h"
#include "OgrePagingLandScapeOptions.h"
#include "OgrePagingLandScapeTextureManager.h"
// Texture loaders implementations
#include "OgrePagingLandScapeTexture.h"
#include "OgrePagingLandScapeTexture_Image.h"
#include "OgrePagingLandScapeTexture_InstantBaseTexture.h"
#include "OgrePagingLandScapeTexture_BaseTexture.h"
#include "OgrePagingLandScapeTexture_BaseTexture2.h"
#include "OgrePagingLandScapeTexture_Splatting.h"
#include "OgrePagingLandScapeTexture_Splatting2.h"
#include "OgrePagingLandScapeTexture_Splatting3.h"
#include "OgrePagingLandScapeTexture_Splatting4.h"
#include "OgrePagingLandScapeTexture_Splatting5.h"
#include "OgrePagingLandScapeTexture_Splatting6.h"
#include "OgrePagingLandScapeTexture_Splatting7.h"
namespace Ogre
{
//-----------------------------------------------------------------------
template<> PagingLandScapeTextureManager* Singleton<PagingLandScapeTextureManager>::ms_Singleton = 0;
PagingLandScapeTextureManager* PagingLandScapeTextureManager::getSingletonPtr(void)
{
return ms_Singleton;
}
PagingLandScapeTextureManager& PagingLandScapeTextureManager::getSingleton(void)
{
assert( ms_Singleton ); return ( *ms_Singleton );
}
//-----------------------------------------------------------------------
PagingLandScapeTextureManager::PagingLandScapeTextureManager( )
{
uint w = PagingLandScapeOptions::getSingleton().world_width;
uint h = PagingLandScapeOptions::getSingleton().world_height;
uint i, j;
//Setup the page array
// mTexture.reserve (w);
// mTexture.resize (w);
for ( i = 0; i < w; i++)
{
mTexture.push_back( PagingLandScapeTextureRow() );
// mTexture[i].reserve (h);
// mTexture[i].resize (h);
for (j = 0; j < h; j++ )
{
mTexture[i].push_back( 0);
}
}
//Populate the page array
PagingLandScapeTexture* data;
if ( PagingLandScapeOptions::getSingleton().textureFormat == "Image" )
{
for ( j = 0; j < h; j++ )
{
for ( i = 0; i < w; i++ )
{
data = new PagingLandScapeTexture_Image();
mTexture[ i ][ j ] = data;
}
}
}
else if ( PagingLandScapeOptions::getSingleton().textureFormat == "BaseTexture" )
{
for ( j = 0; j < h; j++ )
{
for ( i = 0; i < w; i++ )
{
data = new PagingLandScapeTexture_BaseTexture();
mTexture[ i ][ j ] = data;
}
}
}
else if ( PagingLandScapeOptions::getSingleton().textureFormat == "BaseTexture2" )
{
for ( j = 0; j < h; j++ )
{
for ( i = 0; i < w; i++ )
{
data = new PagingLandScapeTexture_BaseTexture2();
mTexture[ i ][ j ] = data;
}
}
}
else if ( PagingLandScapeOptions::getSingleton().textureFormat == "InstantBaseTexture" )
{
for ( j = 0; j < h; j++ )
{
for ( i = 0; i < w; i++ )
{
data = new PagingLandScapeTexture_InstantBaseTexture();
mTexture[ i ][ j ] = data;
}
}
}
else if ( PagingLandScapeOptions::getSingleton().textureFormat == "Splatting" )
{
if (Root::getSingleton().getRenderSystem()->getName () != "Direct3D9 Rendering SubSystem")
{
Except(1, "DirectX9 renderer is need for this splatting method, "
"so cannot run this splatting method. Sorry!",
"PagingLandScapeTextureManager");
}
for ( j = 0; j < h; j++ )
{
for ( i = 0; i < w; i++ )
{
data = new PagingLandScapeTexture_Splatting();
mTexture[ i ][ j ] = data;
}
}
}
else if ( PagingLandScapeOptions::getSingleton().textureFormat == "Splatting2" )
{
if (Root::getSingleton().getRenderSystem()->getName () != "Direct3D9 Rendering SubSystem")
{
Except(1, "DirectX9 renderer is need for this splatting method, "
"so cannot run this splatting method. Sorry!",
"PagingLandScapeTextureManager");
}
for ( j = 0; j < h; j++ )
{
for ( i = 0; i < w; i++ )
{
data = new PagingLandScapeTexture_Splatting2();
mTexture[ i ][ j ] = data;
}
}
}
else if ( PagingLandScapeOptions::getSingleton().textureFormat == "Splatting3" )
{
if (Root::getSingleton().getRenderSystem()->getName () != "OpenGL Rendering Subsystem")
{
Except(1, "OpenGL renderer is need for this splatting method, "
"so cannot run this splatting method. Sorry!",
"PagingLandScapeTextureManager");
}
for ( j = 0; j < h; j++ )
{
for ( i = 0; i < w; i++ )
{
data = new PagingLandScapeTexture_Splatting3();
mTexture[ i ][ j ] = data;
}
}
}
else if ( PagingLandScapeOptions::getSingleton().textureFormat == "Splatting4" )
{
if (Root::getSingleton().getRenderSystem()->getName () != "Direct3D9 Rendering SubSystem")
{
Except(1, "DirectX9 renderer is need for this splatting method, "
"so cannot run this splatting method. Sorry!",
"PagingLandScapeTextureManager");
}
for ( j = 0; j < h; j++ )
{
for ( i = 0; i < w; i++ )
{
data = new PagingLandScapeTexture_Splatting4();
mTexture[ i ][ j ] = data;
}
}
}
else if ( PagingLandScapeOptions::getSingleton().textureFormat == "Splatting5" )
{
if (Root::getSingleton().getRenderSystem()->getName () != "OpenGL Rendering Subsystem")
{
Except(1, "OpenGL renderer is need for this splatting method, "
"so cannot run this splatting method. Sorry!",
"PagingLandScapeTextureManager");
}
const RenderSystemCapabilities* caps = Root::getSingleton().getRenderSystem()->getCapabilities();
if (!(caps->hasCapability(RSC_FRAGMENT_PROGRAM)))
{
Except(1, "Your card does not support advanced fragment programs (openGL pixel shader), "
"so cannot run this splatting method. Sorry!",
"PagingLandScapeTextureManager");
}
if (!(GpuProgramManager::getSingleton().isSyntaxSupported("arbfp1")))
{
Except(1, "Your card does not support advanced fragment programs (openGL pixel shader), "
"so cannot run this splatting method. Sorry!",
"PagingLandScapeTextureManager");
}
for ( j = 0; j < h; j++ )
{
for ( i = 0; i < w; i++ )
{
data = new PagingLandScapeTexture_Splatting5();
mTexture[ i ][ j ] = data;
}
}
}
else if ( PagingLandScapeOptions::getSingleton().textureFormat == "Splatting6" )
{
if (Root::getSingleton().getRenderSystem()->getName () != "Direct3D9 Rendering SubSystem")
{
Except(1, "DirectX9 renderer is need for this splatting method, "
"so cannot run this splatting method. Sorry!",
"PagingLandScapeTextureManager");
}
for ( j = 0; j < h; j++ )
{
for ( i = 0; i < w; i++ )
{
data = new PagingLandScapeTexture_Splatting6();
mTexture[ i ][ j ] = data;
}
}
}
else if ( PagingLandScapeOptions::getSingleton().textureFormat == "Splatting7" )
{
if (Root::getSingleton().getRenderSystem()->getName () != "Direct3D9 Rendering SubSystem")
{
Except(1, "DirectX9 renderer is need for this splatting method, "
"so cannot run this splatting method. Sorry!",
"PagingLandScapeTextureManager");
}
const RenderSystemCapabilities* caps = Root::getSingleton().getRenderSystem()->getCapabilities();
if (caps->getNumTextureUnits () < 7)
{
Except(1, "Your card does not have enough Texture Units, "
"so cannot run this splatting method. Sorry!",
"PagingLandScapeTextureManager");
}
for ( j = 0; j < h; j++ )
{
for ( i = 0; i < w; i++ )
{
data = new PagingLandScapeTexture_Splatting7();
mTexture[ i ][ j ] = data;
}
}
}
else
{
data = 0;
Except( Exception::ERR_INVALIDPARAMS, "PageTexture not supplied!", "PagingLandScapeTextureManager::PagingLandScapeTextureManager" );
}
}
//-----------------------------------------------------------------------
PagingLandScapeTextureManager::~PagingLandScapeTextureManager( )
{
PagingLandScapeTexturePages::iterator iend = mTexture.end();
for (PagingLandScapeTexturePages::iterator i = mTexture.begin(); i != iend; ++i)
{
PagingLandScapeTextureRow::iterator jend = i->end();
for (PagingLandScapeTextureRow::iterator j = i->begin(); j != jend; ++j)
{
delete *j;
*j = 0;
}
i->clear();
}
mTexture.clear();
}
//-----------------------------------------------------------------------
void PagingLandScapeTextureManager::load( const uint dataX, const uint dataZ )
{
PagingLandScapeTexture* data = mTexture[ dataX ][ dataZ ];
if ( !data->isLoaded() )
{
data->load( dataX, dataZ );
}
}
//-----------------------------------------------------------------------
void PagingLandScapeTextureManager::unload( const uint dataX, const uint dataZ )
{
PagingLandScapeTexture* data = mTexture[ dataX ][ dataZ ];
if ( data->isLoaded() )
{
data->unload();
}
}
//-----------------------------------------------------------------------
bool PagingLandScapeTextureManager::isLoaded( const uint dataX, const uint dataZ )
{
return mTexture[ dataX ][ dataZ ]->isLoaded();
}
//-----------------------------------------------------------------------
Material* PagingLandScapeTextureManager::getMaterial( const uint dataX, const uint dataZ )
{
return mTexture[ dataX ][ dataZ ]->getMaterial();
}
} //namespace
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -