什么是Ogre-Paged?
PagedGeometry是一个Ogre优化大场景中大量实体渲染的一个工具,特别适合于密集的森林以及室外场景,这些大场景中往往有成千上万的树木,灌木,草,石头等等等。
Paged geometry拥有众多的渲染优势,最大的一点在于——速度。如果使用恰当的话,室外场景的渲染效率可以达到提高100倍甚至更多。同时,静态场景是分页的,那么每一次只需要当前需要的对应实体,这也就提供了一种扩展室外场景到很大范围的可能,甚至构建一个无穷大的虚拟世界。
Example均为官方文档里面附带的教程
Example1
我们按照Ogre的基本框架首先加入如下代码作为主函数
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR strCmdLine, INT nCmdShow)
#else
int main(int argc, char *argv[])
#endif
{
//Initialize Ogre
Root *root = new Ogre::Root("");
//Load appropriate plugins
//[NOTE] PagedGeometry needs the CgProgramManager plugin to compile shaders
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#ifdef _DEBUG
root->loadPlugin("Plugin_CgProgramManager_d");
root->loadPlugin("Plugin_OctreeSceneManager_d");
root->loadPlugin("RenderSystem_Direct3D9_d");
root->loadPlugin("RenderSystem_GL_d");
#else
root->loadPlugin("Plugin_CgProgramManager");
root->loadPlugin("Plugin_OctreeSceneManager");
root->loadPlugin("RenderSystem_Direct3D9");
root->loadPlugin("RenderSystem_GL");
#endif
#else
root->loadPlugin("Plugin_CgProgramManager");
root->loadPlugin("Plugin_OctreeSceneManager");
root->loadPlugin("RenderSystem_GL");
#endif
//Show Ogre's default config dialog to let the user setup resolution, etc.
bool result = root->showConfigDialog();
//If the user clicks OK, continue
if (result) {
World myWorld;
myWorld.load(); //Load world
myWorld.run(); //Display world
}
//Shut down Ogre
delete root;
return 0;
}
其中,class World代表了整个世界,定义如下:
class World
{
public:
World();
~World();
void load(); //Loads the 3D scene
void unload(); //Unloads the 3D scene cleanly
void run(); //Runs the simulation
private:
void render(); //Renders a single frame, updating PagedGeometry and Ogre
void processInput(); //Accepts keyboard and mou