32 #include <OgreOverlaySystem.h>
33 #include <OgreOverlayManager.h>
34 #include <OgreOverlay.h>
45 m_rtt_texture = Ogre::TextureManager::getSingleton().getByName(
"EnvironmentTexture");
47 for (
int face = 0; face < NUM_FACES; face++)
49 m_render_targets[face] = m_rtt_texture->getBuffer(face)->getRenderTarget();
51 m_cameras[face]->setAspectRatio(1.0);
52 m_cameras[face]->setProjectionType(Ogre::PT_PERSPECTIVE);
53 m_cameras[face]->setFixedYawAxis(
false);
54 m_cameras[face]->setFOVy(Ogre::Degree(90));
55 m_cameras[face]->setNearClipDistance(0.1f);
58 Ogre::Viewport* v = m_render_targets[face]->addViewport(m_cameras[face]);
59 v->setOverlaysEnabled(
false);
60 v->setClearEveryFrame(
true);
62 m_render_targets[face]->setAutoUpdated(
false);
65 m_cameras[0]->setDirection(+Ogre::Vector3::UNIT_X);
66 m_cameras[1]->setDirection(-Ogre::Vector3::UNIT_X);
67 m_cameras[2]->setDirection(+Ogre::Vector3::UNIT_Y);
68 m_cameras[3]->setDirection(-Ogre::Vector3::UNIT_Y);
69 m_cameras[4]->setDirection(-Ogre::Vector3::UNIT_Z);
70 m_cameras[5]->setDirection(+Ogre::Vector3::UNIT_Z);
75 Ogre::Overlay* overlay = Ogre::OverlayManager::getSingleton().create(
"EnvMapDebugOverlay");
78 Ogre::Vector3 position = Ogre::Vector3::ZERO;
81 Ogre::MeshPtr mesh = Ogre::MeshManager::getSingletonPtr()->createManual(
"cubeMapDebug", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
83 Ogre::SubMesh* sub = mesh->createSubMesh();
86 sub->operationType = Ogre::RenderOperation::OT_TRIANGLE_LIST;
88 sub->useSharedVertices =
true;
89 mesh->sharedVertexData =
new Ogre::VertexData;
90 sub->indexData =
new Ogre::IndexData;
94 mesh->sharedVertexData->vertexDeclaration->addElement(0, offset, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
95 offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
96 mesh->sharedVertexData->vertexDeclaration->addElement(0, offset, Ogre::VET_FLOAT3, Ogre::VES_TEXTURE_COORDINATES);
99 mesh->sharedVertexData->vertexCount = 14;
100 Ogre::HardwareVertexBufferSharedPtr vertexBuffer =
101 Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(
102 mesh->sharedVertexData->vertexDeclaration->getVertexSize(0),
103 mesh->sharedVertexData->vertexCount,
104 Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
105 mesh->sharedVertexData->vertexBufferBinding->setBinding(0, vertexBuffer);
108 static const float vertexData[] = {
110 0.0, 2.0, -1.0, 1.0, 1.0,
111 0.0, 1.0, -1.0, -1.0, 1.0,
112 1.0, 2.0, -1.0, 1.0, -1.0,
113 1.0, 1.0, -1.0, -1.0, -1.0,
114 2.0, 2.0, 1.0, 1.0, -1.0,
115 2.0, 1.0, 1.0, -1.0, -1.0,
116 3.0, 2.0, 1.0, 1.0, 1.0,
117 3.0, 1.0, 1.0, -1.0, 1.0,
118 4.0, 2.0, -1.0, 1.0, 1.0,
119 4.0, 1.0, -1.0, -1.0, 1.0,
120 1.0, 3.0, -1.0, 1.0, 1.0,
121 2.0, 3.0, 1.0, 1.0, 1.0,
122 1.0, 0.0, -1.0, -1.0, 1.0,
123 2.0, 0.0, 1.0, -1.0, 1.0,
127 float* pData =
static_cast<float*
>(vertexBuffer->lock(Ogre::HardwareBuffer::HBL_DISCARD));
128 for (
size_t vertex = 0, i = 0; vertex < mesh->sharedVertexData->vertexCount; vertex++)
131 *pData++ = position.x + scale * vertexData[i++];
132 *pData++ = position.y + scale * vertexData[i++];
136 *pData++ = vertexData[i++];
137 *pData++ = vertexData[i++];
138 *pData++ = vertexData[i++];
140 vertexBuffer->unlock();
143 sub->indexData->indexCount = 36;
144 Ogre::HardwareIndexBufferSharedPtr indexBuffer =
145 Ogre::HardwareBufferManager::getSingleton().createIndexBuffer(
146 Ogre::HardwareIndexBuffer::IT_16BIT,
147 sub->indexData->indexCount,
148 Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
149 sub->indexData->indexBuffer = indexBuffer;
152 static const Ogre::uint16 indexData[] = {
169 indexBuffer->writeData(0, indexBuffer->getSizeInBytes(), indexData,
true);
171 mesh->_setBounds(Ogre::AxisAlignedBox::BOX_INFINITE);
172 mesh->_setBoundingSphereRadius(10);
176 e->setCastShadows(
false);
177 e->setRenderQueueGroup(Ogre::RENDER_QUEUE_OVERLAY - 1);
180 e->setMaterialName(
"tracks/EnvMapDebug");
181 Ogre::SceneNode* mDebugSceneNode =
new Ogre::SceneNode(
App::GetGfxScene()->GetSceneManager());
182 mDebugSceneNode->attachObject(e);
183 mDebugSceneNode->setPosition(Ogre::Vector3(0, 0, -5));
184 mDebugSceneNode->setFixedYawAxis(
true, Ogre::Vector3::UNIT_Y);
185 mDebugSceneNode->setVisible(
true);
186 mDebugSceneNode->_update(
true,
true);
187 mDebugSceneNode->_updateBounds();
188 overlay->add3D(mDebugSceneNode);
196 for (
int face = 0; face < NUM_FACES; face++)
198 if (m_cameras[face] !=
nullptr)
201 m_render_targets[face]->removeAllViewports();
221 if (!full && update_rate == 0)
226 for (
int i = 0; i < NUM_FACES; i++)
228 m_cameras[i]->setPosition(center);
231 if (gfx_actor !=
nullptr)
237 for (
int i = 0; i < update_rate; i++)
246 m_render_targets[m_update_round]->update();
247 m_update_round = (m_update_round + 1) % NUM_FACES;
256 if (gfx_actor !=
nullptr)