163Engine* Engine::instance =
nullptr;
164Renderer* Engine::renderer =
nullptr;
174Engine::AnimationProcessingTarget Engine::animationProcessingTarget = Engine::AnimationProcessingTarget::CPU;
183Engine* Engine::currentEngine =
nullptr;
184bool Engine::skinningShaderEnabled =
false;
185int Engine::threadCount = 0;
186bool Engine::have4K =
false;
187float Engine::animationBlendingTime = 250.0f;
188int32_t Engine::shadowMapWidth = 0;
189int32_t Engine::shadowMapHeight = 0;
190int32_t Engine::shadowMapRenderLookUps = 0;
191int32_t Engine::environmentMappingWidth = 1024;
192int32_t Engine::environmentMappingHeight = 1024;
193float Engine::transformationsComputingReduction1Distance = 25.0f;
194float Engine::transformationsComputingReduction2Distance = 50.0f;
195map<string, Engine::Shader> Engine::shaders;
196unordered_map<string, uint8_t> Engine::uniqueShaderIds;
198vector<Engine::EngineThread*> Engine::engineThreads;
200Engine::EngineThreadQueueElementPool Engine::engineThreadQueueElementPool;
211 Console::println(
"EngineThread::" +
string(__FUNCTION__) +
"()[" + to_string(idx) +
"]: INIT");
212 while (isStopRequested() ==
false) {
213 auto element = queue->getElement();
214 if (element ==
nullptr)
continue;
215 switch(element->type) {
219 element->engine->preRenderFunction(
223 element->objects.clear();
227 element->engine->computeTransformationsFunction(
231 element->objects.clear();
235 element->engine->entityRenderer->renderFunction(
237 element->rendering.renderPass,
239 objectsByShadersAndModels,
240 element->rendering.collectTransparentFaces,
241 element->rendering.renderTypes,
242 transparentRenderFacesPool
244 element->objects.clear();
249 Console::println(
"EngineThread::" +
string(__FUNCTION__) +
"()[" + to_string(idx) +
"]: DONE");
313 Console::println(
string(
"Engine::createOffScreenInstance(): Engine not created or not initialized."));
317 auto offScreenEngine =
new Engine();
318 offScreenEngine->initialized =
true;
323 offScreenEngine->entityRenderer->initialize();
327 offScreenEngine->frameBuffer->initialize();
332 for (
auto i = 0; i < offScreenEngine->lights.size(); i++) {
334 offScreenEngine->lights[i].setSourceTexture(TextureReader::read(
"resources/engine/textures",
"sun.png"));
338 offScreenEngine->shadowMapping =
new ShadowMapping(offScreenEngine,
renderer, offScreenEngine->entityRenderer);
343 offScreenEngine->geometryBuffer->initialize();
347 return offScreenEngine;
360 if (this->partition !=
nullptr && this->partition !=
partition)
delete this->
partition;
370 if (entity == entityByIdIt->second) {
371 Console::println(
"Engine::addEntity(): " + entity->
getId() +
": entity already added!");
428 if (particleSystemEntity !=
nullptr && particleSystemEntity->isAutoEmit() ==
true) {
435 array<vector<Object3D*>, 5> objectsArray = {
442 for (
auto& objects: objectsArray) {
443 for (
auto object3D: objects) {
458 auto entity = entityByIdIt->second;
468 if (entity->isFrustumCulling() ==
true && entity->isEnabled() ==
true)
partition->
removeEntity(entity);
475 entity->setEngine(
nullptr);
476 entity->setRenderer(
nullptr);
485 decomposedEntities.
objects.erase(
487 decomposedEntities.
objects.begin(),
488 decomposedEntities.
objects.end(),
491 decomposedEntities.
objects.end()
525 decomposedEntities.
opses.erase(
527 decomposedEntities.
opses.begin(),
528 decomposedEntities.
opses.end(),
531 decomposedEntities.
opses.end()
533 decomposedEntities.
ppses.erase(
535 decomposedEntities.
ppses.begin(),
536 decomposedEntities.
ppses.end(),
539 decomposedEntities.
ppses.end()
541 decomposedEntities.
psgs.erase(
543 decomposedEntities.
psgs.begin(),
544 decomposedEntities.
psgs.end(),
547 decomposedEntities.
psgs.end()
617 if (entity ==
nullptr)
return;
625 for (
auto subEntity: ops->getObjects()) {
631 for (
auto subEntity: eh->getEntities()) {
648 for (
auto subEntity: lob3dImposter->getLOD2Object()->getBillboardObjects())
removeEntityFromLists(subEntity);
654 vector<string> entitiesToRemove;
656 auto entityKey = it.first;
657 entitiesToRemove.push_back(entityKey);
659 for (
auto entityKey: entitiesToRemove) {
678 renderer = Application::getRenderer();
681 Console::println(
"No renderer: Exiting!");
682 Application::exit(0);
698 if (
threadCount == 0)
threadCount = Math::clamp(Thread::getHardwareThreadCount() == 0?3:Thread::getHardwareThreadCount() / 2, 2, 3);
703 Console::println(
string(
"TDME2::Thread count: ") + to_string(
threadCount));
706 ObjectBuffer::initialize();
719 Console::println(
string(
"TDME2::Renderer::Graphics Vendor: ") +
renderer->
getVendor());
720 Console::println(
string(
"TDME2::Renderer::Graphics Renderer: ") +
renderer->
getRenderer());
725 GUIParser::initialize();
737 for (
auto i = 0; i <
lights.size(); i++) {
739 lights[i].setSourceTexture(TextureReader::read(
"resources/engine/textures",
"sun.png"));
784 Console::println(
"TDME2::VBOs are available.");
786 Console::println(
"TDME2::VBOs are not available! Engine will not work!");
792 Console::println(
"TDME2::Basic FBOs are not available!");
795 Console::println(
"TDME2::Basic FBOs are available.");
804 Console::println(
"TDME2::Using shadow mapping");
811 Console::println(
"TDME2::Not using shadow mapping");
816 Console::println(
"TDME2::Using skinning compute shader");
820 Console::println(
"TDME2::Not using skinning compute shader");
823 #define CHECK_INITIALIZED(NAME, SHADER) if (SHADER != nullptr && SHADER->isInitialized() == false) Console::println(string("TDME: ") + NAME + ": Not initialized")
853 Console::println(
"TDME2::Using deferred shading");
855 Console::println(
"TDME2::Not using deferred shading");
859 Console::println(
string(
"TDME2::initialized & ready: ") + to_string(
initialized));
863 Console::println(
"Engine not initialized: Exiting!");
864 Application::exit(0);
954 reshape(this->width, this->height);
972 decomposedEntites.
objects.clear();
977 decomposedEntites.
opses.clear();
978 decomposedEntites.
ppses.clear();
979 decomposedEntites.
psgs.clear();
1003 for (
auto object: objects)
object->preRender(threadIdx);
1007 for (
auto object: objects)
object->computeTransformations(threadIdx);
1014 auto object =
static_cast<Object3D*
>(entity);
1015 if (object->isDisableDepthTest() ==
true) {
1021 if (object->isNeedsForwardShading() ==
true &&
1026 decomposedEntities.
objects.push_back(
object);
1028 if (object->isEnableEarlyZRejection() ==
true) {
1029 decomposedEntities.
ezrObjects.push_back(
object);
1035 auto lodObject =
static_cast<LODObject3D*
>(entity);
1036 if (decomposeAllEntities ==
true) {
1038 auto lod2Object = lodObject->getLOD2Object();
1039 auto lod3Object = lodObject->getLOD3Object();
1044 auto object = lodObject->determineLODObject(
camera);
1045 if (
object !=
nullptr)
decomposeEntityType(
object, decomposedEntities, decomposeAllEntities);
1052 if (decomposeAllEntities ==
true) {
1053 for (
auto subEntity: imposterObject->getBillboardObjects())
decomposeEntityType(subEntity, decomposedEntities);
1062 if (decomposeAllEntities ==
true) {
1064 for (
auto subEntity: lodObjectImposter->getLOD2Object()->getBillboardObjects())
decomposeEntityType(subEntity, decomposedEntities);
1066 auto object = lodObjectImposter->determineLODObject(
camera);
1067 if (
object !=
nullptr)
decomposeEntityType(
object, decomposedEntities, decomposeAllEntities);
1074 if (decomposeAllEntities ==
true) {
1075 for (
auto object: opse->getObjects())
decomposeEntityType(
object, decomposedEntities, decomposeAllEntities);
1077 for (
auto object: opse->getEnabledObjects())
decomposeEntityType(
object, decomposedEntities, decomposeAllEntities);
1079 decomposedEntities.
opses.push_back(opse);
1085 decomposedEntities.
ppses.push_back(ppse);
1091 decomposedEntities.
ppses.push_back(fpse);
1110 auto subEntity = org->getEntity();
1111 if (subEntity !=
nullptr)
decomposeEntityType(subEntity, decomposedEntities, decomposeAllEntities);
1117 decomposedEntities.
psgs.push_back(psg); \
1118 for (
auto ps: psg->getParticleSystems())
decomposeEntityType(ps, decomposedEntities, decomposeAllEntities);
1125 for (
auto entityEh: eh->getEntities()) {
1126 if (entityEh->isEnabled() ==
false && decomposeAllEntities ==
false)
continue;
1137 for (
auto entity: entities) {
1145 if (autoEmit ==
true) {
1150 if (pse->isEnabled() ==
false)
continue;
1154 pse->updateParticles();
1185 if (entity->isEnabled() ==
false)
continue;
1204 auto elementsIssued = 0;
1207 queueElement->engine =
this;
1212 auto queueElementToSubmit = queueElement;
1215 queueElement->engine =
this;
1221 if (queueElement->objects.empty() ==
false) {
1227 queueElement->engine =
this;
1232 auto queueElementToSubmit = queueElement;
1235 queueElement->engine =
this;
1241 if (queueElement->objects.empty() ==
false) {
1244 queueElement =
nullptr;
1248 while (
true ==
true) {
1249 auto elementsProcessed = 0;
1250 for (
auto engineThread:
Engine::engineThreads) elementsProcessed+= engineThread->getProcessedElements();
1251 if (elementsProcessed == elementsIssued) {
1276 action->performAction();
1316 effectPassFrameBuffersInUse.fill(
false);
1320 if (program ==
nullptr)
continue;
1321 for (
auto& effectPass: program->getEffectPasses()) {
1322 auto effectPassIdx = effectPass.effectPassIdx;
1323 auto frameBufferIdx = effectPass.effectPassIdx - 1;
1324 auto frameBufferWidth = _width / effectPass.frameBufferWidthDivideFactor;
1325 auto frameBufferHeight = _height / effectPass.frameBufferHeightDivideFactor;
1334 effectPassFrameBuffersInUse[frameBufferIdx] =
true;
1339 effectPass.clearColor.getRed(),
1340 effectPass.clearColor.getGreen(),
1341 effectPass.clearColor.getBlue(),
1342 effectPass.clearColor.getAlpha()
1348 auto lightSourceVisible =
false;
1349 if (effectPass.renderLightSources ==
true) {
1352 if (effectPass.skipOnLightSourceNotVisible ==
true && lightSourceVisible ==
false) {
1362 effectPass.shaderPrefix,
1368 EntityRenderer::RENDERTYPE_TEXTUREARRAYS_DIFFUSEMASKEDTRANSPARENCY |
1369 EntityRenderer::RENDERTYPE_MATERIALS_DIFFUSEMASKEDTRANSPARENCY |
1370 EntityRenderer::RENDERTYPE_TEXTURES_DIFFUSEMASKEDTRANSPARENCY
1377 for (
auto i = 0; i < effectPassFrameBuffersInUse.size(); i++) {
1438 EntityRenderer::RENDERTYPE_NORMALS |
1439 EntityRenderer::RENDERTYPE_TEXTUREARRAYS |
1440 EntityRenderer::RENDERTYPE_TEXTUREARRAYS_DIFFUSEMASKEDTRANSPARENCY |
1441 EntityRenderer::RENDERTYPE_EFFECTCOLORS |
1442 EntityRenderer::RENDERTYPE_MATERIALS |
1443 EntityRenderer::RENDERTYPE_MATERIALS_DIFFUSEMASKEDTRANSPARENCY |
1444 EntityRenderer::RENDERTYPE_TEXTURES |
1445 EntityRenderer::RENDERTYPE_TEXTURES_DIFFUSEMASKEDTRANSPARENCY |
1446 EntityRenderer::RENDERTYPE_LIGHTS
1478 (2.0f * (mouseX * scaleFactorWidth) / _width) - 1.0f,
1479 1.0f - (2.0f * (mouseY * scaleFactorHeight) / _height),
1484 worldCoordinate4.
scale(1.0f / worldCoordinate4.getW());
1486 worldCoordinate4.getX(),
1487 worldCoordinate4.getY(),
1488 worldCoordinate4.getZ()
1519 Node** object3DNode,
1525 Vector3 boundingBoxLineContactMin;
1526 Vector3 boundingBoxLineContactMax;
1530 auto selectedEntityDistance = Float::MAX_VALUE;
1531 Entity* selectedEntity =
nullptr;
1532 Node* selectedObject3DNode =
nullptr;
1538 if (forcePicking ==
false && entity->isPickable() ==
false)
continue;
1539 if (filter !=
nullptr && filter->
filterEntity(entity) ==
false)
continue;
1541 if (LineSegment::doesBoundingBoxCollideWithLineSegment(entity->getBoundingBoxTransformed(), nearPlaneWorldCoordinate, farPlaneWorldCoordinate, boundingBoxLineContactMin, boundingBoxLineContactMax) ==
true) {
1542 for (
auto it = entity->getTransformedFacesIterator()->iterator(); it->hasNext();) {
1543 auto& vertices = it->next();
1544 if (LineSegment::doesLineSegmentCollideWithTriangle(vertices[0], vertices[1], vertices[2], nearPlaneWorldCoordinate, farPlaneWorldCoordinate, lineTriangleContact) ==
true) {
1547 if (selectedEntity ==
nullptr || entityDistance < selectedEntityDistance) {
1548 selectedEntity = entity;
1549 selectedEntityDistance = entityDistance;
1550 selectedObject3DNode = it->getNode();
1551 selectedParticleSystem =
nullptr;
1558 if (selectedEntity !=
nullptr) {
1559 if (object3DNode !=
nullptr) *object3DNode = selectedObject3DNode;
1560 for (
auto _entity = selectedEntity; _entity !=
nullptr; _entity = _entity->
getParentEntity()) {
1561 if (_entity->getParentEntity() ==
nullptr)
return _entity;
1567 for (
auto entity: decomposedEntities.
opses) {
1569 if (forcePicking ==
false && entity->isPickable() ==
false)
continue;
1570 if (filter !=
nullptr && filter->
filterEntity(entity) ==
false)
continue;
1572 if (LineSegment::doesBoundingBoxCollideWithLineSegment(entity->getBoundingBoxTransformed(), nearPlaneWorldCoordinate, farPlaneWorldCoordinate, boundingBoxLineContactMin, boundingBoxLineContactMax) ==
true) {
1573 auto entityDistance = lineTriangleContact.
set(entity->getBoundingBoxTransformed()->getCenter()).
sub(nearPlaneWorldCoordinate).
computeLengthSquared();
1575 if (selectedEntity ==
nullptr || entityDistance < selectedEntityDistance) {
1576 selectedEntity = entity;
1577 selectedEntityDistance = entityDistance;
1578 selectedObject3DNode =
nullptr;
1579 selectedParticleSystem =
nullptr;
1585 for (
auto entity: decomposedEntities.
ppses) {
1587 if (forcePicking ==
false && entity->isPickable() ==
false)
continue;
1588 if (filter !=
nullptr && filter->
filterEntity(entity) ==
false)
continue;
1590 if (LineSegment::doesBoundingBoxCollideWithLineSegment(entity->getBoundingBoxTransformed(), nearPlaneWorldCoordinate, farPlaneWorldCoordinate, boundingBoxLineContactMin, boundingBoxLineContactMax) ==
true) {
1591 auto entityDistance = lineTriangleContact.
set(entity->getBoundingBoxTransformed()->getCenter()).
sub(nearPlaneWorldCoordinate).
computeLengthSquared();
1593 if (selectedEntity ==
nullptr || entityDistance < selectedEntityDistance) {
1594 selectedEntity = entity;
1595 selectedEntityDistance = entityDistance;
1596 selectedObject3DNode =
nullptr;
1597 selectedParticleSystem =
nullptr;
1603 for (
auto entity: decomposedEntities.
psgs) {
1605 if (forcePicking ==
false && entity->isPickable() ==
false)
continue;
1606 if (filter !=
nullptr && filter->
filterEntity(entity) ==
false)
continue;
1608 if (LineSegment::doesBoundingBoxCollideWithLineSegment(entity->getBoundingBoxTransformed(), nearPlaneWorldCoordinate, farPlaneWorldCoordinate, boundingBoxLineContactMin, boundingBoxLineContactMax) ==
true) {
1609 auto entityDistance = lineTriangleContact.
set(entity->getBoundingBoxTransformed()->getCenter()).
sub(nearPlaneWorldCoordinate).
computeLengthSquared();
1611 if (selectedEntity ==
nullptr || entityDistance < selectedEntityDistance) {
1612 selectedEntity = entity;
1613 selectedEntityDistance = entityDistance;
1614 selectedObject3DNode =
nullptr;
1615 selectedParticleSystem =
nullptr;
1616 auto selectedSubEntityDistance = Float::MAX_VALUE;
1618 for (
auto subEntity: entity->getParticleSystems()) {
1619 if (LineSegment::doesBoundingBoxCollideWithLineSegment(subEntity->getBoundingBoxTransformed(), nearPlaneWorldCoordinate, farPlaneWorldCoordinate, boundingBoxLineContactMin, boundingBoxLineContactMax) ==
true) {
1620 auto subEntityDistance = lineTriangleContact.
set(subEntity->getBoundingBoxTransformed()->getCenter()).
sub(nearPlaneWorldCoordinate).
computeLengthSquared();
1622 if (selectedParticleSystem ==
nullptr || subEntityDistance < selectedSubEntityDistance) {
1623 selectedSubEntityDistance = subEntityDistance;
1624 selectedParticleSystem = subEntity;
1635 if (forcePicking ==
false && entity->isPickable() ==
false)
continue;
1636 if (filter !=
nullptr && filter->
filterEntity(entity) ==
false)
continue;
1638 if (LineSegment::doesBoundingBoxCollideWithLineSegment(entity->getBoundingBoxTransformed(), nearPlaneWorldCoordinate, farPlaneWorldCoordinate, boundingBoxLineContactMin, boundingBoxLineContactMax) ==
true) {
1639 auto entityDistance = lineTriangleContact.
set(entity->getBoundingBoxTransformed()->getCenter()).
sub(nearPlaneWorldCoordinate).
computeLengthSquared();
1641 if (selectedEntity ==
nullptr || entityDistance < selectedEntityDistance) {
1642 selectedEntity = entity;
1643 selectedEntityDistance = entityDistance;
1644 selectedObject3DNode =
nullptr;
1645 selectedParticleSystem =
nullptr;
1652 for (
auto& objects: objectsArray) {
1653 for (
auto entity: objects) {
1655 if (forcePicking ==
false && entity->isPickable() ==
false)
continue;
1656 if (filter !=
nullptr && filter->
filterEntity(entity) ==
false)
continue;
1658 if (LineSegment::doesBoundingBoxCollideWithLineSegment(entity->getBoundingBoxTransformed(), nearPlaneWorldCoordinate, farPlaneWorldCoordinate, boundingBoxLineContactMin, boundingBoxLineContactMax) ==
true) {
1659 for (
auto it = entity->getTransformedFacesIterator()->iterator(); it->hasNext();) {
1660 auto& vertices = it->next();
1661 if (LineSegment::doesLineSegmentCollideWithTriangle(vertices[0], vertices[1], vertices[2], nearPlaneWorldCoordinate, farPlaneWorldCoordinate, lineTriangleContact) ==
true) {
1664 if (selectedEntity ==
nullptr || entityDistance < selectedEntityDistance) {
1665 selectedEntity = entity;
1666 selectedEntityDistance = entityDistance;
1667 selectedObject3DNode = it->getNode();
1668 selectedParticleSystem =
nullptr;
1677 for (
auto entity: decomposedEntities.
lodObjects) {
1679 if (forcePicking ==
false && entity->isPickable() ==
false)
continue;
1680 if (filter !=
nullptr && filter->
filterEntity(entity) ==
false)
continue;
1682 if (LineSegment::doesBoundingBoxCollideWithLineSegment(entity->getBoundingBoxTransformed(), nearPlaneWorldCoordinate, farPlaneWorldCoordinate, boundingBoxLineContactMin, boundingBoxLineContactMax) ==
true) {
1683 auto object = entity->getLODObject();
1684 if (
object !=
nullptr) {
1685 for (
auto it = object->getTransformedFacesIterator()->iterator(); it->hasNext();) {
1686 auto& vertices = it->next();
1687 if (LineSegment::doesLineSegmentCollideWithTriangle(vertices[0], vertices[1], vertices[2], nearPlaneWorldCoordinate, farPlaneWorldCoordinate, lineTriangleContact) ==
true) {
1690 if (selectedEntity ==
nullptr || entityDistance < selectedEntityDistance) {
1691 selectedEntity = entity;
1692 selectedEntityDistance = entityDistance;
1695 selectedObject3DNode = it->getNode();
1696 selectedParticleSystem =
nullptr;
1705 if (forcePicking ==
false && entity->isPickable() ==
false)
continue;
1706 if (filter !=
nullptr && filter->
filterEntity(entity) ==
false)
continue;
1708 if (LineSegment::doesBoundingBoxCollideWithLineSegment(entity->getBoundingBoxTransformed(), nearPlaneWorldCoordinate, farPlaneWorldCoordinate, boundingBoxLineContactMin, boundingBoxLineContactMax) ==
true) {
1710 Node* object3DNodeEH =
nullptr;
1713 entity->getEntities(),
1714 decomposedEntitiesEH
1717 decomposedEntitiesEH,
1723 &particleSystemEntityEH
1725 if (subEntity !=
nullptr) {
1726 auto entityDistance = lineTriangleContact.
set(subEntity->getBoundingBoxTransformed()->getCenter()).
sub(nearPlaneWorldCoordinate).
computeLengthSquared();
1728 if (selectedEntity ==
nullptr || entityDistance < selectedEntityDistance) {
1729 selectedEntity = entity;
1730 selectedEntityDistance = entityDistance;
1731 selectedObject3DNode = object3DNodeEH;
1732 selectedParticleSystem = particleSystemEntityEH;
1739 if (object3DNode !=
nullptr) *object3DNode = selectedObject3DNode;
1742 if (particleSystemEntity !=
nullptr) {
1743 *particleSystemEntity = selectedParticleSystem;
1747 if (selectedEntity !=
nullptr) {
1748 for (
auto _entity = selectedEntity; _entity !=
nullptr; _entity = _entity->
getParentEntity()) {
1749 if (_entity->getParentEntity() ==
nullptr)
return _entity;
1763 return doRayCasting(startPoint, endPoint, contactPoint, filter);
1773 Vector3 boundingBoxLineContactMin;
1774 Vector3 boundingBoxLineContactMax;
1778 auto selectedEntityDistance = Float::MAX_VALUE;
1779 Entity* selectedEntity =
nullptr;
1784 if (forcePicking ==
false && entity->isPickable() ==
false)
continue;
1785 if (filter !=
nullptr && filter->
filterEntity(entity) ==
false)
continue;
1787 if (LineSegment::doesBoundingBoxCollideWithLineSegment(entity->getBoundingBoxTransformed(), startPoint, endPoint, boundingBoxLineContactMin, boundingBoxLineContactMax) ==
true) {
1788 for (
auto it = entity->getTransformedFacesIterator()->iterator(); it->hasNext();) {
1789 auto& vertices = it->next();
1790 if (LineSegment::doesLineSegmentCollideWithTriangle(vertices[0], vertices[1], vertices[2], startPoint, endPoint, lineTriangleContact) ==
true) {
1793 if (selectedEntity ==
nullptr || entityDistance < selectedEntityDistance) {
1794 selectedEntity = entity;
1795 selectedEntityDistance = entityDistance;
1796 contactPoint = lineTriangleContact;
1803 if (selectedEntity !=
nullptr) {
1804 return selectedEntity;
1809 for (
auto& objects: objectsArray) {
1810 for (
auto entity: objects) {
1812 if (forcePicking ==
false && entity->isPickable() ==
false)
continue;
1813 if (filter !=
nullptr && filter->
filterEntity(entity) ==
false)
continue;
1815 if (LineSegment::doesBoundingBoxCollideWithLineSegment(entity->getBoundingBoxTransformed(), startPoint, endPoint, boundingBoxLineContactMin, boundingBoxLineContactMax) ==
true) {
1816 for (
auto it = entity->getTransformedFacesIterator()->iterator(); it->hasNext();) {
1817 auto& vertices = it->next();
1818 if (LineSegment::doesLineSegmentCollideWithTriangle(vertices[0], vertices[1], vertices[2], startPoint, endPoint, lineTriangleContact) ==
true) {
1821 if (selectedEntity ==
nullptr || entityDistance < selectedEntityDistance) {
1822 selectedEntity = entity;
1823 selectedEntityDistance = entityDistance;
1824 contactPoint = lineTriangleContact;
1833 for (
auto entity: decomposedEntities.
lodObjects) {
1835 if (forcePicking ==
false && entity->isPickable() ==
false)
continue;
1836 if (filter !=
nullptr && filter->
filterEntity(entity) ==
false)
continue;
1838 if (LineSegment::doesBoundingBoxCollideWithLineSegment(entity->getBoundingBoxTransformed(), startPoint, endPoint, boundingBoxLineContactMin, boundingBoxLineContactMax) ==
true) {
1839 auto object = entity->getLODObject();
1840 if (
object !=
nullptr) {
1841 for (
auto it = object->getTransformedFacesIterator()->iterator(); it->hasNext();) {
1842 auto& vertices = it->next();
1843 if (LineSegment::doesLineSegmentCollideWithTriangle(vertices[0], vertices[1], vertices[2], startPoint, endPoint, lineTriangleContact) ==
true) {
1846 if (selectedEntity ==
nullptr || entityDistance < selectedEntityDistance) {
1847 selectedEntity = entity;
1848 selectedEntityDistance = entityDistance;
1849 contactPoint = lineTriangleContact;
1860 if (forcePicking ==
false && entity->isPickable() ==
false)
continue;
1861 if (filter !=
nullptr && filter->
filterEntity(entity) ==
false)
continue;
1863 if (LineSegment::doesBoundingBoxCollideWithLineSegment(entity->getBoundingBoxTransformed(), startPoint, endPoint, boundingBoxLineContactMin, boundingBoxLineContactMax) ==
true) {
1866 entity->getEntities(),
1867 decomposedEntitiesEH
1871 decomposedEntitiesEH,
1878 if (entity !=
nullptr) {
1881 if (selectedEntity ==
nullptr || entityDistance < selectedEntityDistance) {
1882 selectedEntity = entity;
1883 selectedEntityDistance = entityDistance;
1884 contactPoint = contactPointEH;
1891 return selectedEntity;
1900 screenCoordinate4.
scale(1.0f / screenCoordinate4.getW());
1902 screenCoordinate.
setX((screenCoordinate4[0] + 1.0f) * _width / 2.0f);
1903 screenCoordinate.
setY(_height - ((screenCoordinate4[1] + 1.0f) * _height / 2.0f));
1913 vector<string> entitiesToRemove;
1915 auto entityKey = it.first;
1916 entitiesToRemove.push_back(entityKey);
1918 for (
auto entityKey: entitiesToRemove) {
1935 GUIParser::dispose();
1943 ObjectBuffer::dispose();
1978 if (pixels ==
nullptr) {
1979 Console::println(
"Engine::makeScreenshot(): Failed to read pixels");
1985 "tdme.engine.makescreenshot",
1993 texture->acquireReference();
1994 PNGTextureWriter::write(texture, pathName, fileName, removeAlphaChannel);
1995 texture->releaseReference();
2011 if (pixels ==
nullptr) {
2012 Console::println(
"Engine::makeScreenshot(): Failed to read pixels");
2018 "tdme.engine.makescreenshot",
2027 texture->acquireReference();
2028 PNGTextureWriter::write(texture, pngData);
2029 texture->releaseReference();
2048 auto postProcessingFrameBufferIdx = 0;
2051 if (program ==
nullptr)
continue;
2052 if (program->getRenderPass() != renderPass)
continue;
2053 auto effectPassSkipDetected =
false;
2054 for (
auto& effectPass: program->getEffectPasses()) {
2055 if (
effectPassSkip[effectPass.effectPassIdx - 1] ==
true) effectPassSkipDetected =
true;
2057 if (effectPassSkipDetected ==
true)
continue;
2058 for (
auto& step: program->getPostProcessingSteps()) {
2059 auto shaderId = step.shaderId;
2063 if (step.blendToSource == PostProcessingProgram::FRAMEBUFFERSOURCE_SCREEN) {
2064 blendToSource = postProcessingFrameBuffers[postProcessingFrameBufferIdx];
2066 switch(step.source) {
2067 case PostProcessingProgram::FRAMEBUFFERSOURCE_NONE:
2069 case PostProcessingProgram::FRAMEBUFFERSOURCE_SCREEN:
2070 source = postProcessingFrameBuffers[postProcessingFrameBufferIdx];
2076 switch(step.target) {
2077 case PostProcessingProgram::FRAMEBUFFERTARGET_SCREEN:
2078 target = postProcessingFrameBuffers[(postProcessingFrameBufferIdx + 1) % 2];
2080 case PostProcessingProgram::FRAMEBUFFERTARGET_TEMPORARY:
2090 switch(step.target) {
2091 case PostProcessingProgram::FRAMEBUFFERTARGET_SCREEN:
2092 postProcessingFrameBufferIdx = (postProcessingFrameBufferIdx + 1) % 2;
2094 case PostProcessingProgram::FRAMEBUFFERTARGET_TEMPORARY:
2101 if (postProcessingFrameBuffers[postProcessingFrameBufferIdx] != targetFrameBuffer) {
2102 if (targetFrameBuffer !=
nullptr) {
2107 postProcessingFrameBuffers[postProcessingFrameBufferIdx]->renderToScreen(
this);
2112 vector<string> result;
2113 for (
auto shadersIt:
shaders) {
2114 auto& shader = shadersIt.second;
2115 if (shader.type == type) {
2116 result.push_back(shader.id);
2124 Console::println(
"Engine::registerShader(): Shader already registered: " + shaderId);
2130 .parameterDefaults = parameterDefaults
2135 auto shaderIt =
shaders.find(shaderId);
2136 if (shaderIt ==
shaders.end()) {
2137 Console::println(
"Engine::getShaderParameterDefaults(): No registered shader: " + shaderId);
2138 return map<string, ShaderParameter>();
2140 return shaderIt->second.parameterDefaults;
2143void Engine::render(
FrameBuffer* renderFrameBuffer,
GeometryBuffer* renderGeometryBuffer,
DecomposedEntities&
visibleDecomposedEntities, int32_t effectPass, int32_t renderPassMask,
const string& shaderPrefix,
bool useEZR,
bool applyShadowMapping,
bool applyPostProcessing,
bool doRenderLightSource,
bool doRenderParticleSystems, int32_t renderTypes) {
2157 if ((renderPassMask & renderPass) == renderPass) {
2162 ((renderTypes & EntityRenderer::RENDERTYPE_TEXTUREARRAYS_DIFFUSEMASKEDTRANSPARENCY) == EntityRenderer::RENDERTYPE_TEXTUREARRAYS_DIFFUSEMASKEDTRANSPARENCY?EntityRenderer::RENDERTYPE_TEXTUREARRAYS_DIFFUSEMASKEDTRANSPARENCY:0) |
2163 ((renderTypes & EntityRenderer::RENDERTYPE_TEXTURES_DIFFUSEMASKEDTRANSPARENCY) == EntityRenderer::RENDERTYPE_TEXTURES_DIFFUSEMASKEDTRANSPARENCY?EntityRenderer::RENDERTYPE_TEXTURES_DIFFUSEMASKEDTRANSPARENCY:0)
2181 if ((renderPassMask & renderPass) == renderPass) {
2183 if (renderGeometryBuffer !=
nullptr) {
2197 ((renderTypes & EntityRenderer::RENDERTYPE_NORMALS) == EntityRenderer::RENDERTYPE_NORMALS?EntityRenderer::RENDERTYPE_NORMALS:0) |
2198 ((renderTypes & EntityRenderer::RENDERTYPE_TEXTUREARRAYS) == EntityRenderer::RENDERTYPE_TEXTUREARRAYS?EntityRenderer::RENDERTYPE_TEXTUREARRAYS:0) |
2199 ((renderTypes & EntityRenderer::RENDERTYPE_TEXTUREARRAYS_DIFFUSEMASKEDTRANSPARENCY) == EntityRenderer::RENDERTYPE_TEXTUREARRAYS_DIFFUSEMASKEDTRANSPARENCY?EntityRenderer::RENDERTYPE_TEXTUREARRAYS_DIFFUSEMASKEDTRANSPARENCY:0) |
2200 ((renderTypes & EntityRenderer::RENDERTYPE_EFFECTCOLORS) == EntityRenderer::RENDERTYPE_EFFECTCOLORS?EntityRenderer::RENDERTYPE_EFFECTCOLORS:0) |
2201 ((renderTypes & EntityRenderer::RENDERTYPE_MATERIALS) == EntityRenderer::RENDERTYPE_MATERIALS?EntityRenderer::RENDERTYPE_MATERIALS:0) |
2202 ((renderTypes & EntityRenderer::RENDERTYPE_MATERIALS_DIFFUSEMASKEDTRANSPARENCY) == EntityRenderer::RENDERTYPE_MATERIALS_DIFFUSEMASKEDTRANSPARENCY?EntityRenderer::RENDERTYPE_MATERIALS_DIFFUSEMASKEDTRANSPARENCY:0) |
2203 ((renderTypes & EntityRenderer::RENDERTYPE_TEXTURES) == EntityRenderer::RENDERTYPE_TEXTURES?EntityRenderer::RENDERTYPE_TEXTURES:0) |
2204 ((renderTypes & EntityRenderer::RENDERTYPE_TEXTURES_DIFFUSEMASKEDTRANSPARENCY) == EntityRenderer::RENDERTYPE_TEXTURES_DIFFUSEMASKEDTRANSPARENCY?EntityRenderer::RENDERTYPE_TEXTURES_DIFFUSEMASKEDTRANSPARENCY:0)|
2205 ((renderTypes & EntityRenderer::RENDERTYPE_LIGHTS) == EntityRenderer::RENDERTYPE_LIGHTS?EntityRenderer::RENDERTYPE_LIGHTS:0)
2208 if (renderGeometryBuffer !=
nullptr) {
2222 ((renderTypes & EntityRenderer::RENDERTYPE_NORMALS) == EntityRenderer::RENDERTYPE_NORMALS?EntityRenderer::RENDERTYPE_NORMALS:0) |
2223 ((renderTypes & EntityRenderer::RENDERTYPE_TEXTUREARRAYS) == EntityRenderer::RENDERTYPE_TEXTUREARRAYS?EntityRenderer::RENDERTYPE_TEXTUREARRAYS:0) |
2224 ((renderTypes & EntityRenderer::RENDERTYPE_TEXTUREARRAYS_DIFFUSEMASKEDTRANSPARENCY) == EntityRenderer::RENDERTYPE_TEXTUREARRAYS_DIFFUSEMASKEDTRANSPARENCY?EntityRenderer::RENDERTYPE_TEXTUREARRAYS_DIFFUSEMASKEDTRANSPARENCY:0) |
2225 ((renderTypes & EntityRenderer::RENDERTYPE_EFFECTCOLORS) == EntityRenderer::RENDERTYPE_EFFECTCOLORS?EntityRenderer::RENDERTYPE_EFFECTCOLORS:0) |
2226 ((renderTypes & EntityRenderer::RENDERTYPE_MATERIALS) == EntityRenderer::RENDERTYPE_MATERIALS?EntityRenderer::RENDERTYPE_MATERIALS:0) |
2227 ((renderTypes & EntityRenderer::RENDERTYPE_MATERIALS_DIFFUSEMASKEDTRANSPARENCY) == EntityRenderer::RENDERTYPE_MATERIALS_DIFFUSEMASKEDTRANSPARENCY?EntityRenderer::RENDERTYPE_MATERIALS_DIFFUSEMASKEDTRANSPARENCY:0) |
2228 ((renderTypes & EntityRenderer::RENDERTYPE_TEXTURES) == EntityRenderer::RENDERTYPE_TEXTURES?EntityRenderer::RENDERTYPE_TEXTURES:0) |
2229 ((renderTypes & EntityRenderer::RENDERTYPE_TEXTURES_DIFFUSEMASKEDTRANSPARENCY) == EntityRenderer::RENDERTYPE_TEXTURES_DIFFUSEMASKEDTRANSPARENCY?EntityRenderer::RENDERTYPE_TEXTURES_DIFFUSEMASKEDTRANSPARENCY:0)|
2230 ((renderTypes & EntityRenderer::RENDERTYPE_LIGHTS) == EntityRenderer::RENDERTYPE_LIGHTS?EntityRenderer::RENDERTYPE_LIGHTS:0)
2237 ((renderTypes & EntityRenderer::RENDERTYPE_NORMALS) == EntityRenderer::RENDERTYPE_NORMALS?EntityRenderer::RENDERTYPE_NORMALS:0) |
2238 ((renderTypes & EntityRenderer::RENDERTYPE_TEXTUREARRAYS) == EntityRenderer::RENDERTYPE_TEXTUREARRAYS?EntityRenderer::RENDERTYPE_TEXTUREARRAYS:0) |
2239 ((renderTypes & EntityRenderer::RENDERTYPE_TEXTUREARRAYS_DIFFUSEMASKEDTRANSPARENCY) == EntityRenderer::RENDERTYPE_TEXTUREARRAYS_DIFFUSEMASKEDTRANSPARENCY?EntityRenderer::RENDERTYPE_TEXTUREARRAYS_DIFFUSEMASKEDTRANSPARENCY:0) |
2240 ((renderTypes & EntityRenderer::RENDERTYPE_EFFECTCOLORS) == EntityRenderer::RENDERTYPE_EFFECTCOLORS?EntityRenderer::RENDERTYPE_EFFECTCOLORS:0) |
2241 ((renderTypes & EntityRenderer::RENDERTYPE_MATERIALS) == EntityRenderer::RENDERTYPE_MATERIALS?EntityRenderer::RENDERTYPE_MATERIALS:0) |
2242 ((renderTypes & EntityRenderer::RENDERTYPE_MATERIALS_DIFFUSEMASKEDTRANSPARENCY) == EntityRenderer::RENDERTYPE_MATERIALS_DIFFUSEMASKEDTRANSPARENCY?EntityRenderer::RENDERTYPE_MATERIALS_DIFFUSEMASKEDTRANSPARENCY:0) |
2243 ((renderTypes & EntityRenderer::RENDERTYPE_TEXTURES) == EntityRenderer::RENDERTYPE_TEXTURES?EntityRenderer::RENDERTYPE_TEXTURES:0) |
2244 ((renderTypes & EntityRenderer::RENDERTYPE_TEXTURES_DIFFUSEMASKEDTRANSPARENCY) == EntityRenderer::RENDERTYPE_TEXTURES_DIFFUSEMASKEDTRANSPARENCY?EntityRenderer::RENDERTYPE_TEXTURES_DIFFUSEMASKEDTRANSPARENCY:0)|
2245 ((renderTypes & EntityRenderer::RENDERTYPE_LIGHTS) == EntityRenderer::RENDERTYPE_LIGHTS?EntityRenderer::RENDERTYPE_LIGHTS:0)
2261 if (applyShadowMapping ==
true &&
shadowMapping !=
nullptr) {
2268 if (applyPostProcessing ==
true) {
2309 if (applyPostProcessing ==
true) {
2325 if ((renderPassMask & renderPass) == renderPass) {
2331 ((renderTypes & EntityRenderer::RENDERTYPE_NORMALS) == EntityRenderer::RENDERTYPE_NORMALS?EntityRenderer::RENDERTYPE_NORMALS:0) |
2332 ((renderTypes & EntityRenderer::RENDERTYPE_TEXTUREARRAYS) == EntityRenderer::RENDERTYPE_TEXTUREARRAYS?EntityRenderer::RENDERTYPE_TEXTUREARRAYS:0) |
2333 ((renderTypes & EntityRenderer::RENDERTYPE_TEXTUREARRAYS_DIFFUSEMASKEDTRANSPARENCY) == EntityRenderer::RENDERTYPE_TEXTUREARRAYS_DIFFUSEMASKEDTRANSPARENCY?EntityRenderer::RENDERTYPE_TEXTUREARRAYS_DIFFUSEMASKEDTRANSPARENCY:0) |
2334 ((renderTypes & EntityRenderer::RENDERTYPE_EFFECTCOLORS) == EntityRenderer::RENDERTYPE_EFFECTCOLORS?EntityRenderer::RENDERTYPE_EFFECTCOLORS:0) |
2335 ((renderTypes & EntityRenderer::RENDERTYPE_MATERIALS) == EntityRenderer::RENDERTYPE_MATERIALS?EntityRenderer::RENDERTYPE_MATERIALS:0) |
2336 ((renderTypes & EntityRenderer::RENDERTYPE_MATERIALS_DIFFUSEMASKEDTRANSPARENCY) == EntityRenderer::RENDERTYPE_MATERIALS_DIFFUSEMASKEDTRANSPARENCY?EntityRenderer::RENDERTYPE_MATERIALS_DIFFUSEMASKEDTRANSPARENCY:0) |
2337 ((renderTypes & EntityRenderer::RENDERTYPE_TEXTURES) == EntityRenderer::RENDERTYPE_TEXTURES?EntityRenderer::RENDERTYPE_TEXTURES:0) |
2338 ((renderTypes & EntityRenderer::RENDERTYPE_TEXTURES_DIFFUSEMASKEDTRANSPARENCY) == EntityRenderer::RENDERTYPE_TEXTURES_DIFFUSEMASKEDTRANSPARENCY?EntityRenderer::RENDERTYPE_TEXTURES_DIFFUSEMASKEDTRANSPARENCY:0)|
2339 ((renderTypes & EntityRenderer::RENDERTYPE_LIGHTS) == EntityRenderer::RENDERTYPE_LIGHTS?EntityRenderer::RENDERTYPE_LIGHTS:0)
2352 if (applyShadowMapping ==
true &&
shadowMapping !=
nullptr) {
2370 if ((renderPassMask & renderPass) == renderPass) {
2376 ((renderTypes & EntityRenderer::RENDERTYPE_NORMALS) == EntityRenderer::RENDERTYPE_NORMALS?EntityRenderer::RENDERTYPE_NORMALS:0) |
2377 ((renderTypes & EntityRenderer::RENDERTYPE_TEXTUREARRAYS) == EntityRenderer::RENDERTYPE_TEXTUREARRAYS?EntityRenderer::RENDERTYPE_TEXTUREARRAYS:0) |
2378 ((renderTypes & EntityRenderer::RENDERTYPE_TEXTUREARRAYS_DIFFUSEMASKEDTRANSPARENCY) == EntityRenderer::RENDERTYPE_TEXTUREARRAYS_DIFFUSEMASKEDTRANSPARENCY?EntityRenderer::RENDERTYPE_TEXTUREARRAYS_DIFFUSEMASKEDTRANSPARENCY:0) |
2379 ((renderTypes & EntityRenderer::RENDERTYPE_EFFECTCOLORS) == EntityRenderer::RENDERTYPE_EFFECTCOLORS?EntityRenderer::RENDERTYPE_EFFECTCOLORS:0) |
2380 ((renderTypes & EntityRenderer::RENDERTYPE_MATERIALS) == EntityRenderer::RENDERTYPE_MATERIALS?EntityRenderer::RENDERTYPE_MATERIALS:0) |
2381 ((renderTypes & EntityRenderer::RENDERTYPE_MATERIALS_DIFFUSEMASKEDTRANSPARENCY) == EntityRenderer::RENDERTYPE_MATERIALS_DIFFUSEMASKEDTRANSPARENCY?EntityRenderer::RENDERTYPE_MATERIALS_DIFFUSEMASKEDTRANSPARENCY:0) |
2382 ((renderTypes & EntityRenderer::RENDERTYPE_TEXTURES) == EntityRenderer::RENDERTYPE_TEXTURES?EntityRenderer::RENDERTYPE_TEXTURES:0) |
2383 ((renderTypes & EntityRenderer::RENDERTYPE_TEXTURES_DIFFUSEMASKEDTRANSPARENCY) == EntityRenderer::RENDERTYPE_TEXTURES_DIFFUSEMASKEDTRANSPARENCY?EntityRenderer::RENDERTYPE_TEXTURES_DIFFUSEMASKEDTRANSPARENCY:0)|
2384 ((renderTypes & EntityRenderer::RENDERTYPE_LIGHTS) == EntityRenderer::RENDERTYPE_LIGHTS?EntityRenderer::RENDERTYPE_LIGHTS:0)
2400 if (applyShadowMapping ==
true &&
shadowMapping !=
nullptr) {
2405 if (doRenderLightSource ==
true) {
2418 auto lightSourceVisible =
false;
2419 for (
auto& light:
lights) {
2420 if (light.isEnabled() ==
false || light.isRenderSource() ==
false)
continue;
2421 auto lightSourceSize = light.getSourceSize();
2422 auto lightSourcePixelSize = width < height?static_cast<float>(lightSourceSize) *
static_cast<float>(
width):
static_cast<float>(lightSourceSize) *
static_cast<float>(
height);;
2423 Vector2 lightSourceDimension2D =
Vector2(lightSourcePixelSize, lightSourcePixelSize);
2424 Vector2 lightSourcePosition2D;
2425 Vector3 lightSourcePosition =
Vector3(light.getPosition().getX(), light.getPosition().getY(), light.getPosition().getZ());
2426 if (light.getPosition().getW() > Math::EPSILON) lightSourcePosition.
scale(1.0f / light.getPosition().getW());
2428 lightSourcePosition2D.
sub(lightSourceDimension2D.
clone().
scale(0.5f));
2429 if (visible ==
true) {
2431 lightSourceVisible =
true;
2434 return lightSourceVisible;
2438 for (
auto shaderType = 0; shaderType <
SHADERTYPE_MAX; shaderType++)
2440 string shaderTypeString =
"unknowm";
2441 switch (shaderType) {
2446 Console::println(
string(
"TDME2::registered " + shaderTypeString +
" shader: ") + shaderId);
2448 if (defaultShaderParameters.size() > 0) {
2449 Console::print(
"\t");
2450 for (
auto it: defaultShaderParameters) {
2451 auto& parameterName = it.first;
2452 Console::print(parameterName);
2453 switch(it.second.getType()) {
2455 Console::print(
"=none; ");
2458 Console::print(
"=boolean(");
2459 Console::print(
getShaderParameter(shaderId, parameterName).getBooleanValue() ==
true?
"true":
"false");
2460 Console::print(
"); ");
2463 Console::print(
"=integer(");
2464 Console::print(to_string(
getShaderParameter(shaderId, parameterName).getIntegerValue()));
2465 Console::print(
"); ");
2468 Console::print(
"=float(");
2469 Console::print(to_string(
getShaderParameter(shaderId, parameterName).getFloatValue()));
2470 Console::print(
"); ");
2474 Console::print(
"=Vector2(");
2476 for (
auto i = 0; i < shaderParameterArray.size(); i++) {
2477 if (i != 0) Console::print(
",");
2478 Console::print(to_string(shaderParameterArray[i]));
2480 Console::print(
"); ");
2485 Console::print(
"=Vector3(");
2487 for (
auto i = 0; i < shaderParameterArray.size(); i++) {
2488 if (i != 0) Console::print(
",");
2489 Console::print(to_string(shaderParameterArray[i]));
2491 Console::print(
"); ");
2496 Console::print(
"=Vector4(");
2498 for (
auto i = 0; i < shaderParameterArray.size(); i++) {
2499 if (i != 0) Console::print(
",");
2500 Console::print(to_string(shaderParameterArray[i]));
2502 Console::print(
"); ");
2506 Console::print(
"=unknown; ");
#define CHECK_INITIALIZED(NAME, SHADER)
Application base class, please make sure to allocate application on heap to have correct application ...
const Matrix4x4 & getModelViewProjectionInvertedMatrix() const
void update(int contextIdx, int32_t width, int32_t height)
Sets up camera while resizing the view port.
const Matrix4x4 & getModelViewMatrix() const
const Matrix4x4 & getModelViewProjectionMatrix() const
TransparentRenderFacesPool * transparentRenderFacesPool
static void setShadowMapRenderLookUps(int32_t shadowMapRenderLookUps)
Set shadowmap look ups for each pixel when rendering.
static STATIC_DLL_IMPEXT Engine * currentEngine
bool renderLightSources(int width, int height)
Render light sources.
void dumpShaders()
Print registered shaders and it default parameters to console.
bool removeEntity(const string &id)
Removes an entity.
static STATIC_DLL_IMPEXT MeshManager * meshManager
unordered_set< Entity * > needsPreRenderEntities
bool renderingComputedTransformations
static STATIC_DLL_IMPEXT Renderer * renderer
static STATIC_DLL_IMPEXT EZRShader * ezrShader
static STATIC_DLL_IMPEXT TextureManager * textureManager
static STATIC_DLL_IMPEXT Queue< EngineThreadQueueElement > * engineThreadsQueue
void initRendering()
Initiates the rendering process updates timing, updates camera.
void doPostProcessing(PostProcessingProgram::RenderPass renderPass, const array< FrameBuffer *, 2 > postProcessingFrameBuffers, FrameBuffer *targetFrameBuffer)
Do post processing.
void reshape(int32_t width, int32_t height)
Reshape.
void display()
Renders the scene.
static STATIC_DLL_IMPEXT LightingShader * lightingShader
static STATIC_DLL_IMPEXT vector< EngineThread * > engineThreads
void initialize()
Initialize render engine.
bool makeScreenshot(const string &pathName, const string &fileName, bool removeAlphaChannel=true)
Creates a PNG file from current screen( This does not seem to work with GLES2 and offscreen engines.
static STATIC_DLL_IMPEXT int threadCount
static const vector< string > getRegisteredShader(ShaderType type)
Returns registered shaders for given type.
void computeTransformationsFunction(vector< Object3D * > &objects, int threadIdx)
Computes visibility and transformations.
array< Light, LIGHTS_MAX > lights
GeometryBuffer * geometryBuffer
void render(FrameBuffer *renderFrameBuffer, GeometryBuffer *renderGeometryBuffer, DecomposedEntities &visibleDecomposedEntities, int32_t effectPass, int32_t renderPassMask, const string &shaderPrefix, bool useEZR, bool applyShadowMapping, bool applyPostProcessing, bool doRenderLightSource, bool doRenderParticleSystems, int32_t renderTypes)
Do a render/effect pass.
static STATIC_DLL_IMPEXT bool skinningShaderEnabled
unordered_set< Entity * > noFrustumCullingEntities
void decomposeEntityTypes(const vector< Entity * > &entities, DecomposedEntities &decomposedEntities, bool decomposeAllEntities=false)
Decompose entity types.
Vector3 computeWorldCoordinateByMousePosition(int32_t mouseX, int32_t mouseY, float z)
Compute world coordinate from mouse position and z value.
void setPartition(Partition *partition)
Set partition.
void addPostProcessingProgram(const string &programId)
Add post processing program.
static STATIC_DLL_IMPEXT AnimationProcessingTarget animationProcessingTarget
void doneGUIMode()
Set up GUI mode rendering.
void initGUIMode()
Set up GUI mode rendering.
void decomposeEntityType(Entity *entity, DecomposedEntities &decomposedEntities, bool decomposeAllEntities=false)
Decompose entity type.
static STATIC_DLL_IMPEXT ShadowMapRenderShader * shadowMappingShaderRender
@ SHADERTYPE_POSTPROCESSING
static void registerShader(ShaderType type, const string &shaderId, const map< string, ShaderParameter > ¶meterDefaults={})
Register shader.
FrameBuffer * postProcessingFrameBuffer1
static STATIC_DLL_IMPEXT LinesShader * linesShader
void removeFromDecomposedEntities(DecomposedEntities &decomposedEntities, Entity *entity)
Remove entity from decomposed entities.
static STATIC_DLL_IMPEXT GUIShader * guiShader
static STATIC_DLL_IMPEXT ParticlesShader * particlesShader
static Engine * createOffScreenInstance(int32_t width, int32_t height, bool enableShadowMapping, bool enableDepthBuffer, bool enableGeometryBuffer)
Creates an offscreen rendering instance Note:
Entity * getEntityByMousePosition(int32_t mouseX, int32_t mouseY, EntityPickingFilter *filter=nullptr, Node **object3DNode=nullptr, ParticleSystemEntity **particleSystemEntity=nullptr)
Retrieves entity by mouse position.
FrameBuffer * postProcessingTemporaryFrameBuffer
static STATIC_DLL_IMPEXT PostProcessingShader * postProcessingShader
void scale(int32_t width, int32_t height)
Scale which applies to main engine only.
static STATIC_DLL_IMPEXT Texture2DRenderShader * texture2DRenderShader
static constexpr int ENGINETHREADSQUEUE_COMPUTE_DISPATCH_COUNT
bool shadowMappingEnabled
static int32_t getShadowMapWidth()
static const map< string, ShaderParameter > getShaderParameterDefaults(const string &shaderId)
Returns parameter defaults of shader with given id.
static STATIC_DLL_IMPEXT map< string, Shader > shaders
Engine()
Private constructor.
void renderToScreen()
Render scaled main engine to screen.
static STATIC_DLL_IMPEXT DeferredLightingRenderShader * deferredLightingRenderShader
static STATIC_DLL_IMPEXT PostProcessing * postProcessing
const string getGraphicsRenderer()
array< bool, EFFECTPASS_COUNT - 1 > effectPassSkip
EntityRenderer * entityRenderer
ShadowMapping * shadowMapping
static int32_t getShadowMapHeight()
unordered_map< string, Entity * > entitiesById
void addEntity(Entity *entity)
Adds an entity by id.
const ShaderParameter getShaderParameter(const string &shaderId, const string ¶meterName)
Returns shader parameter for given shader id and parameter name, if the value does not exist,...
bool computeScreenCoordinateByWorldCoordinate(const Vector3 &worldCoordinate, Vector2 &screenCoordinate, int width=-1, int height=-1)
Convert screen coordinate by world coordinate.
friend class GeometryBuffer
static STATIC_DLL_IMPEXT SkinningShader * skinningShader
static STATIC_DLL_IMPEXT Engine * instance
vector< string > postProcessingPrograms
void resetPostProcessingPrograms()
Clear post processing programs.
void deregisterEntity(Entity *entity)
Removes a entity from internal lists, those entities can also be sub entities from entity hierarchy o...
void dispose()
Shutdown the engine.
void preRenderFunction(vector< Object3D * > &objects, int threadIdx)
Update vertex buffers and such before rendering.
static STATIC_DLL_IMPEXT EngineThreadQueueElementPool engineThreadQueueElementPool
static int32_t getShadowMapRenderLookUps()
static STATIC_DLL_IMPEXT FrameBufferRenderShader * frameBufferRenderShader
Entity * getEntity(const string &id)
Returns a entity by given id.
const string getGraphicsVendor()
static STATIC_DLL_IMPEXT ShadowMapCreationShader * shadowMappingShaderPre
void unscale()
Disable scaling, which applies to main engine only.
static void setShadowMapSize(int32_t width, int32_t height)
Set shadow map size.
unordered_set< Entity * > autoEmitParticleSystemEntities
void reset()
Removes all entities and caches.
FrameBuffer * postProcessingFrameBuffer2
static STATIC_DLL_IMPEXT VBOManager * vboManager
static constexpr int ENGINETHREADSQUEUE_PRERENDER_DISPATCH_COUNT
vector< Action * > actions
void computeTransformations(Camera *camera, DecomposedEntities &decomposedEntites, bool autoEmit, bool computeTransformations)
Computes visibility and transformations.
static STATIC_DLL_IMPEXT GUIRenderer * guiRenderer
FrameBuffer * frameBuffer
void removeEntityFromLists(Entity *entity)
Remove entity.
unordered_set< Entity * > needsComputeTransformationsEntities
bool isUsingPostProcessingTemporaryFrameBuffer
DecomposedEntities visibleDecomposedEntities
void resetLists(DecomposedEntities &decomposedEntites)
Reset lists.
void registerEntity(Entity *entity)
Adds a entity to internal lists, those entities can also be sub entities from entity hierarchy or par...
Entity * doRayCasting(const Vector3 &startPoint, const Vector3 &endPoint, Vector3 &contactPoint, EntityPickingFilter *filter=nullptr)
Does a ray casting of visible 3d object based entities.
array< FrameBuffer *, EFFECTPASS_COUNT - 1 > effectPassFrameBuffers
Entity hierarchy to be used with engine class.
@ RENDERPASS_POST_POSTPROCESSING
virtual bool isEnabled()=0
virtual void setRenderer(Renderer *renderer)=0
Set up renderer.
virtual const string & getId()=0
virtual bool isFrustumCulling()=0
virtual void setEngine(Engine *engine)=0
Set up engine.
virtual EntityType getEntityType()=0
static constexpr int RENDERPASS_ALL
virtual void initialize()=0
Initiates this object 3d.
static constexpr int RENDERPASS_MAX
virtual Entity * getParentEntity()=0
@ ENTITYTYPE_LODOBJECT3DIMPOSTER
@ ENTITYTYPE_OBJECT3DRENDERGROUP
@ ENTITYTYPE_IMPOSTEROBJECT3D
@ ENTITYTYPE_LINESOBJECT3D
@ ENTITYTYPE_OBJECTPARTICLESYSTEM
@ ENTITYTYPE_FOGPARTICLESYSTEM
@ ENTITYTYPE_POINTSPARTICLESYSTEM
@ ENTITYTYPE_ENVIRONMENTMAPPING
@ ENTITYTYPE_PARTICLESYSTEMGROUP
@ ENTITYTYPE_ENTITYHIERARCHY
Environment mapping entity.
Fog particle system entity to be used with engine class.
void reshape(int32_t width, int32_t height)
Resize the frame buffer.
void renderToScreen(Engine *engine, int32_t depthBufferTextureId, int32_t colorBufferTextureId)
Render given depth texture and color buffer texture to screen @parma engine engine.
void initialize()
Initialize the frame buffer.
static void disableFrameBuffer()
Switches back to non offscreen main frame buffer to be rendered.
void enableFrameBuffer()
Enables this frame buffer to be rendered.
static constexpr int32_t FRAMEBUFFER_COLORBUFFER
static void doPostProcessing(Engine *engine, FrameBuffer *target, FrameBuffer *source, const string &programId, const string &shaderId, FrameBuffer *temporary=nullptr, FrameBuffer *blendToSource=nullptr)
Do post processing into target frame buffer (which can be screen as well when passing nullptr)
static constexpr int32_t FRAMEBUFFER_DEPTHBUFFER
void dispose()
Disposes this frame buffer.
void update()
Setups frustum, should be called if frustum did change.
void reshape(int32_t width, int32_t height)
Resize the geometry buffer.
void initialize()
Initialize the geometry buffer.
void renderToScreen(Engine *engine)
Render to screen or bound geometry buffer @engine engine.
void enableGeometryBuffer()
Enables this geometry buffer to be rendered.
static void disableGeometryBuffer()
Switches back to non offscreen main frame buffer to be rendered.
Imposter object 3d to be used with engine class.
LOD object 3D + imposter to be used with engine class.
LOD object 3D to be used with engine class.
Object3D * getLOD1Object()
Object 3D to be used with engine class.
Object 3D render group for static objects that might be animated by shaders.
Object 3D to be used with engine class.
Object particle system entity to be used with engine class.
Oct tree partition implementation.
Particle system group, which combines several particle systems into a group, to be used with engine c...
Point particle system entity to be used with engine class.
Shader parameter model class.
const Vector3 getVector3Value() const
const Vector4 getVector4Value() const
const Vector2 getVector2Value() const
void updateTiming()
Updates timing.
PNG texture writer class.
void set(const array< float, 4 > &color)
Set up color.
Axis aligned bounding box used for frustum, this is not directly connectable with physics engine.
Line segment helper functions.
Early z rejection shader.
void initialize()
Init EZR shader.
void useProgram(Engine *engine)
Use EZR render shader program.
void unUseProgram()
Unuse EZR render shader program.
Deferred lighint render shader.
void initialize()
Initialize.
Frame buffer render shader.
void initialize()
Initialize.
Interface to lighting shader program.
void initialize()
Initialize renderer.
void useProgram(Engine *engine)
Use lighting program.
void unUseProgram()
Unuse lighting program.
void initialize()
Initialize renderer.
void unUseProgram(int contextIdx)
Unuse particles shader program.
void useProgram(int contextIdx)
Use lighting program.
Particles shader program.
void initialize()
Initialize renderer.
void unUseProgram(int contextIdx)
Unuse particles shader program.
void useProgram(int contextIdx)
Use lighting program.
void initialize()
Initialize renderer.
PostProcessingProgram * getPostProcessingProgram(const string &programId)
Get post processing program.
virtual void initializeFrame()=0
Pre Frame Initialization.
virtual void enableDepthBufferTest()=0
Enable depth buffer test.
void setShaderPrefix(const string &shaderPrefix)
Set shader prefix.
virtual bool isSupportingMultithreadedRendering()=0
virtual void finishFrame()=0
Finish frame.
virtual void setClearColor(float red, float green, float blue, float alpha)=0
Set up clear color.
int32_t CLEAR_COLOR_BUFFER_BIT
virtual bool isComputeShaderAvailable()=0
virtual void enableBlending()=0
Enables blending.
virtual void disableBlending()=0
Disables blending.
virtual ByteBuffer * readPixels(int32_t x, int32_t y, int32_t width, int32_t height)=0
Read pixels.
virtual void initGuiMode()=0
Set up renderer for GUI rendering.
virtual bool isBufferObjectsAvailable()=0
Checks if buffer objects is available.
virtual void setColorMask(bool red, bool green, bool blue, bool alpha)=0
Set up GL rendering colormask.
virtual const string getVendor()=0
virtual const string getRenderer()=0
virtual void initialize()=0
Initialize renderer.
virtual void clear(int32_t mask)=0
Clear render buffer with given mask.
virtual bool isDepthTextureAvailable()=0
Checks if depth texture is available.
virtual bool isDeferredShadingAvailable()=0
void setEffectPass(int32_t effectPass)
Set effect pass.
virtual void doneGuiMode()=0
Set up renderer for 3d rendering.
int32_t CONTEXTINDEX_DEFAULT
virtual float readPixelDepth(int32_t x, int32_t y)=0
Reads a pixel depth.
virtual bool isGLCLAvailable()=0
virtual void disableDepthBufferTest()=0
Disable depth buffer test.
int32_t CLEAR_DEPTH_BUFFER_BIT
void render(Entity::RenderPass renderPass, const vector< Object3D * > &objects, bool renderTransparentFaces, int32_t renderTypes)
Renders all given objects.
void reset()
Resets the object 3d renderer.
void renderTransparentFaces()
Renders collected transparent faces.
Buffers used to transfer data between main memory to graphics board memory.
Transparent render faces pool.
Shadow mapping shader to create a shadow map.
void initialize()
Init shadow map creation shader program.
Shadow mapping shader to render shadow maps.
void initialize()
Initialize shadow map render shader program.
void reshape(int32_t width, int32_t height)
Reshape shadow maps.
void createShadowMaps()
Create shadow maps.
void renderShadowMaps(const vector< Object3D * > &visibleObjects)
Render shadow maps to world.
void dispose()
Dispose shadow maps.
Interface to compute shader skinning shader program.
void initialize()
Initialize renderer.
void useProgram()
Use skinning program.
void unUseProgram()
Unuse skinning program.
Texture 2D render shader.
void initialize()
Initialize.
void renderTexture(Engine *engine, const Vector2 &position, const Vector2 &dimension, int textureId, int width=-1, int height=-1)
Render texture.
void reshape(int width, int height)
Reshape.
void initialize()
Init shadow mapping.
Vector3 multiply(const Vector3 &v) const
Multiplies a vector3 with this matrix into destination vector.
Vector2 clone() const
Clones the vector.
Vector2 & scale(const float scale)
Scale this vector.
Vector2 & sub(const Vector2 &v)
Subtracts a vector.
Vector2 & setX(float x)
set X
array< float, 2 > & getArray() const
Vector2 & setY(float y)
set Y
Vector3 & set(float x, float y, float z)
Set up vector.
float computeLengthSquared() const
Vector3 clone() const
Clones the vector.
Vector3 & sub(const Vector3 &v)
Subtracts a vector.
Vector3 & scale(float scale)
Scale this vector.
array< float, 3 > & getArray() const
array< float, 4 > & getArray() const
File system singleton class.
T allocate()
Allocate a new element from pool.
void reset()
Reset this pool.
vector< Object3D * > needsComputeTransformationsEntities
vector< LODObject3D * > lodObjects
vector< Object3D * > objectsPostPostProcessing
vector< EntityHierarchy * > entityHierarchies
vector< LinesObject3D * > linesObjects
vector< Object3D * > objectsForwardShading
vector< EnvironmentMapping * > environmentMappingEntities
vector< ParticleSystemGroup * > psgs
vector< Object3D * > ezrObjects
vector< ObjectParticleSystem * > opses
vector< Object3DRenderGroup * > objectRenderGroups
vector< Object3D * > objects
vector< Object3D * > needsPreRenderEntities
vector< Entity * > noFrustumCullingEntities
vector< Object3D * > objectsNoDepthTest
virtual bool filterEntity(Entity *entity)=0
Filter entity.
Particle system entity interface.
virtual int32_t emitParticles()=0
Adds particles to this particle entity at given position.
virtual bool isVisibleEntity(Entity *entity)=0
Check if entity is visible.
virtual void reset()=0
Reset.
virtual const vector< Entity * > & getVisibleEntities(Frustum *frustum)=0
Get visible entities.
virtual void addEntity(Entity *entity)=0
Adds a entity.
virtual void removeEntity(Entity *entity)=0
Removes a entity.
Entity renderer parameters.