TDME2  1.9.200
Engine.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <algorithm>
4 #include <array>
5 #include <list>
6 #include <memory>
7 #include <string>
8 #include <unordered_map>
9 #include <unordered_set>
10 #include <vector>
11 
12 #include <tdme/tdme.h>
14 #include <tdme/engine/fwd-tdme.h>
16 #include <tdme/engine/Color4.h>
33 #include <tdme/engine/Light.h>
36 #include <tdme/gui/fwd-tdme.h>
39 #include <tdme/math/fwd-tdme.h>
40 #include <tdme/math/Matrix3x3.h>
41 #include <tdme/math/Matrix4x4.h>
44 #include <tdme/utilities/Action.h>
45 #include <tdme/utilities/Console.h>
46 #include <tdme/utilities/Pool.h>
49 
50 using std::array;
51 using std::list;
52 using std::make_unique;
53 using std::remove;
54 using std::sort;
55 using std::string;
56 using std::to_string;
57 using std::unique_ptr;
58 using std::unordered_map;
59 using std::unordered_set;
60 using std::vector;
61 
113 using tdme::gui::GUI;
116 using tdme::math::Vector2;
117 using tdme::math::Vector3;
125 
126 /**
127  * Engine main class
128  * @author Andreas Drewke
129  */
131 {
136  friend class Decal;
137  friend class DynamicColorTexture;
138  friend class EntityHierarchy;
139  friend class EnvironmentMapping;
140  friend class FogParticleSystem;
141  friend class FrameBuffer;
142  friend class GeometryBuffer;
143  friend class ImposterObject;
144  friend class Lines;
145  friend class LODObject;
146  friend class LODObjectImposter;
147  friend class Object;
148  friend class ObjectRenderGroup;
149  friend class ParticleSystemGroup;
150  friend class ObjectParticleSystem;
151  friend class PointsParticleSystem;
177  friend class tdme::gui::GUI;
182 
183 public:
187 
188  // TODO: make sure one can set up this parameter also
189  static constexpr int ENGINETHREADSQUEUE_RENDER_DISPATCH_COUNT { 200 };
191  static constexpr int ENGINETHREADSQUEUE_COMPUTE_DISPATCH_COUNT { 5 };
192 
193  enum LightIdx {
197  LIGHTS_MAX = 8
198  };
199 
200 protected:
202 
203 private:
206 
207  STATIC_DLL_IMPEXT static unique_ptr<TextureManager> textureManager;
208  STATIC_DLL_IMPEXT static unique_ptr<VBOManager> vboManager;
209  STATIC_DLL_IMPEXT static unique_ptr<MeshManager> meshManager;
210  STATIC_DLL_IMPEXT static unique_ptr<GUIRenderer> guiRenderer;
211 
213 
214  STATIC_DLL_IMPEXT static unique_ptr<ShadowMapCreationShader> shadowMappingShaderPre;
215  STATIC_DLL_IMPEXT static unique_ptr<ShadowMapRenderShader> shadowMappingShaderRender;
216  STATIC_DLL_IMPEXT static unique_ptr<LightingShader> lightingShader;
217  STATIC_DLL_IMPEXT static unique_ptr<ParticlesShader> particlesShader;
218  STATIC_DLL_IMPEXT static unique_ptr<LinesShader> linesShader;
219  STATIC_DLL_IMPEXT static unique_ptr<SkinningShader> skinningShader;
220  STATIC_DLL_IMPEXT static unique_ptr<GUIShader> guiShader;
221  STATIC_DLL_IMPEXT static unique_ptr<BRDFLUTShader> brdfLUTShader;
222  STATIC_DLL_IMPEXT static unique_ptr<FrameBufferRenderShader> frameBufferRenderShader;
223  STATIC_DLL_IMPEXT static unique_ptr<DeferredLightingRenderShader> deferredLightingRenderShader;
224  STATIC_DLL_IMPEXT static unique_ptr<SkyRenderShader> skyRenderShader;
225  STATIC_DLL_IMPEXT static unique_ptr<PostProcessing> postProcessing;
226  STATIC_DLL_IMPEXT static unique_ptr<PostProcessingShader> postProcessingShader;
227  STATIC_DLL_IMPEXT static unique_ptr<Texture2DRenderShader> texture2DRenderShader;
238 
239  struct Shader {
241  const string name;
246  };
247  const bool internal;
249  const string id;
250  const vector<ParameterDefaults> parameterDefaults;
251  unordered_map<string, const ParameterDefaults*> parameterDefaultsByName;
252  };
253 
254  STATIC_DLL_IMPEXT static list<Shader> shaders;
255  STATIC_DLL_IMPEXT static unordered_map<string, Shader*> shadersById;
256 
258  vector<Entity*> noFrustumCullingEntities;
259  vector<Object*> objects;
260  vector<Object*> objectsForwardShading;
261  vector<Object*> objectsPostPostProcessing;
262  vector<Object*> objectsNoDepthTest;
263  vector<Object*> objectsGizmo;
264  vector<LODObject*> lodObjects;
265  vector<LODObjectImposter*> lodObjectsImposter;
266  vector<ObjectParticleSystem*> opses;
267  vector<Entity*> ppses;
268  vector<ParticleSystemGroup*> psgs;
269  vector<Lines*> linesEntities;
270  vector<Decal*> decalEntities;
271  vector<ObjectRenderGroup*> objectRenderGroups;
272  vector<EntityHierarchy*> entityHierarchies;
273  vector<EnvironmentMapping*> environmentMappingEntities;
274  vector<Object*> requirePreRenderEntities;
276  };
277 
278  STATIC_DLL_IMPEXT static unordered_map<string, uint8_t> uniqueShaderIds;
279 
280  int32_t width { -1 };
281  int32_t height { -1 };
282  int32_t scaledWidth { -1 };
283  int32_t scaledHeight { -1 };
284  unique_ptr<GUI> gui;
285  unique_ptr<Timing> timing;
286  unique_ptr<Camera> camera;
287  unique_ptr<Camera> gizmoCamera;
288 
289  unique_ptr<Partition> partition;
290 
291  array<unique_ptr<Light>, LIGHTS_MAX> lights;
293  unique_ptr<GeometryBuffer> geometryBuffer;
294  unique_ptr<FrameBuffer> frameBuffer;
295  unique_ptr<FrameBuffer> gizmoFrameBuffer;
296  unique_ptr<FrameBuffer> postProcessingFrameBuffer1;
297  unique_ptr<FrameBuffer> postProcessingFrameBuffer2;
298  unique_ptr<FrameBuffer> postProcessingTemporaryFrameBuffer;
299  array<unique_ptr<FrameBuffer>, EFFECTPASS_COUNT - 1> effectPassFrameBuffers;
301  unique_ptr<ShadowMapping> shadowMapping;
303 
304  unordered_map<string, Entity*> entitiesById;
305 
306  unordered_set<Entity*> autoEmitParticleSystemEntities;
307  unordered_set<Entity*> noFrustumCullingEntities;
308  unordered_set<Entity*> requirePreRenderEntities;
309  unordered_set<Entity*> requireComputeAnimationEntities;
310 
312 
313  unique_ptr<EntityRenderer> entityRenderer;
314 
316 
319 
320  vector<string> postProcessingPrograms;
321 
323 
325 
326  unordered_map<string, unordered_map<string, ShaderParameter>> shaderParameters;
327 
328  TextureAtlas ppsTextureAtlas {"tdme.pps.atlas"};
329  TextureAtlas decalsTextureAtlas {"tdme.decals.atlas"};
330 
331  vector<unique_ptr<Action>> actions;
332 
333  // TODO: put those limits into tdme.h or use dynamic arrays here
334  static constexpr int UNIQUEMODELID_MAX { 2048 };
335  static constexpr int UNIQUEMODELID_NONE { -1 };
336  struct UniqueModelId {
337  int id;
338  int count;
339  };
340  unordered_map<Model*, UniqueModelId> objectUniqueModelIdMapping;
342 
345 
347 
348  Engine* engine { nullptr };
349 
350  struct {
351  bool computeAnimations { false };
353 
354  struct {
356  uint32_t renderTypes;
359 
360  vector<Object*> objects;
361  };
362 
363  class EngineThread: public Thread {
364  friend class Engine;
366  private:
367  int idx;
369  unique_ptr<TransparentRenderFacesPool> transparentRenderFacesPool;
371  volatile int elementsProcessed { 0 };
372 
373  public:
374  /**
375  * Constructor
376  * @param idx thread index
377  * @param queue queue
378  */
380 
381  /**
382  * Run
383  */
384  virtual void run();
385 
386  /**
387  * @return transparent render faces pool
388  */
390  return transparentRenderFacesPool.get();
391  }
392 
393  /**
394  * @return processed elements
395  */
396  inline int getProcessedElements() {
397  return elementsProcessed;
398  }
399 
400  /**
401  * Reset processed element count
402  */
403  inline void resetProcessedElements() {
404  elementsProcessed = 0;
405  }
406 
407  };
408 
409  class EngineThreadQueueElementPool: public Pool<EngineThreadQueueElement> {
410  public:
411  /**
412  * Public constructor
413  */
415  }
416 
417  protected:
418  /**
419  * Instantiate a transparent render face
420  */
422  return new EngineThreadQueueElement();
423  }
424 
425  };
426 
427  STATIC_DLL_IMPEXT static vector<unique_ptr<EngineThread>> engineThreads;
428  STATIC_DLL_IMPEXT static unique_ptr<Queue<EngineThreadQueueElement>> engineThreadsQueue;
430 
431  /**
432  * @return engine
433  */
434  inline static Renderer* getRenderer() {
435  return renderer;
436  }
437 
438  /**
439  * @return mesh manager
440  */
441  inline static MeshManager* getMeshManager() {
442  return meshManager.get();
443  }
444 
445  /**
446  * @return shadow mapping or nullptr if disabled
447  */
449  return shadowMapping.get();
450  }
451 
452  /**
453  * @return particles shader
454  */
456  return particlesShader.get();
457  }
458 
459  /**
460  * @return lines shader
461  */
462  inline static LinesShader* getLinesShader() {
463  return linesShader.get();
464  }
465 
466  /**
467  * @return skinning shader
468  */
470  return skinningShader.get();
471  }
472 
473  /**
474  * @return GUI shader
475  */
476  inline static GUIShader* getGUIShader() {
477  return guiShader.get();
478  }
479 
480  /**
481  * @return BRDF LUT shader
482  */
483  inline static BRDFLUTShader* getBRDFLUTShader() {
484  return brdfLUTShader.get();
485  }
486 
487  /**
488  * @return frame buffer render shader
489  */
491  return frameBufferRenderShader.get();
492  }
493 
494  /**
495  * @return deferred lighting render shader
496  */
498  return deferredLightingRenderShader.get();
499  }
500 
501  /**
502  * @return sky shader
503  */
505  return skyRenderShader.get();
506  }
507 
508  /**
509  * @return entity renderer
510  */
512  return entityRenderer.get();;
513  }
514 
515  /**
516  * @return point particle system texture atlas
517  */
519  return ppsTextureAtlas;
520  }
521 
522  /**
523  * @return decals texture atlas
524  */
526  return decalsTextureAtlas;
527  }
528 
529  // forbid class copy
531 
532  /**
533  * Private constructor
534  */
535  Engine();
536 
537  /**
538  * Decompose entity type
539  * @param entity entity to decompose
540  * @param decomposedEntities decomposed entities
541  * @param decomposeAllEntities decompose all entities, also those who are not rendered right now
542  */
543  void decomposeEntityType(Entity* entity, DecomposedEntities& decomposedEntities, bool decomposeAllEntities = false);
544 
545  /**
546  * Decompose entity types
547  * @param entities given entities to decompose
548  * @param decomposedEntities decomposed entities
549  * @param decomposeAllEntities decompose all entities, also those who are not rendered right now
550  */
552  const vector<Entity*>& entities,
553  DecomposedEntities& decomposedEntities,
554  bool decomposeAllEntities = false
555  );
556 
557  /**
558  * Update vertex buffers and such before rendering
559  * @param objects objects
560  * @param threadIdx thread index
561  */
562  void preRenderFunction(vector<Object*>& objects, int threadIdx);
563 
564  /**
565  * Computes animations
566  * @param objects objects
567  * @param threadIdx thread index
568  */
569  void computeAnimationsFunction(vector<Object*>& objects, int threadIdx);
570 
571  /**
572  * Computes visibility and animations and other pre render steps
573  * @param camera camera
574  * @param decomposedEntities decomposed entities
575  * @param autoEmit auto emit particle systems
576  * @param computeAnimations compute animations
577  */
578  void preRender(Camera* camera, DecomposedEntities& decomposedEntites, bool autoEmit, bool computeAnimations);
579 
580  /**
581  * Set up GUI mode rendering
582  */
583  void initGUIMode();
584 
585  /**
586  * Set up GUI mode rendering
587  */
588  void doneGUIMode();
589 
590  /**
591  * Reset lists
592  * @param decomposedEntities decomposed entities
593  */
594  void resetLists(DecomposedEntities& decomposedEntites);
595 
596  /**
597  * Initiates the rendering process
598  * updates timing, updates camera
599  */
600  void initRendering();
601 
602 public:
603  /**
604  * Destructor
605  */
606  ~Engine();
607 
608  /**
609  * Returns engine instance
610  * @return engine instance
611  */
612  inline static Engine* getInstance() {
613  if (instance == nullptr) {
614  instance = new Engine();
615  }
616  return instance;
617  }
618 
619  /**
620  * Shuts down main engine
621  */
622  static void shutdown();
623 
624  /**
625  * @return texture manager
626  */
628  return Engine::textureManager.get();
629  }
630 
631 
632  /**
633  * @return vertex buffer object manager
634  */
635  inline static VBOManager* getVBOManager() {
636  return vboManager.get();
637  }
638 
639  /**
640  * @return lighting shader
641  */
643  return lightingShader.get();
644  }
645 
646  /**
647  * @return post processing shader
648  */
650  return postProcessingShader.get();
651  }
652 
653  /**
654  * @return shadow mapping shader
655  */
657  return shadowMappingShaderPre.get();
658  }
659 
660  /**
661  * @return shadow mapping shader
662  */
664  return shadowMappingShaderRender.get();
665  }
666 
667  /**
668  * @return engine thread count
669  */
670  inline static int getThreadCount() {
671  return Engine::threadCount;
672  }
673 
674  /**
675  * Set engine thread count
676  * @param threadCount engine thread count
677  */
678  inline static void setThreadCount(int threadCount) {
680  }
681 
682  /**
683  * @return if having 4k
684  */
685  inline static bool is4K() {
686  return Engine::have4K;
687  }
688 
689  /**
690  * Set if having 4k
691  * @param have4K have 4k
692  */
693  inline static void set4K(bool have4K) {
695  }
696 
697  /**
698  * @return animation blending time
699  */
700  inline static float getAnimationBlendingTime() {
702  }
703 
704  /**
705  * Set animation blending time
706  * @param animationBlendingTime animation blending time
707  */
710  }
711 
712  /**
713  * @return shadow map light eye distance scale
714  */
717  }
718 
719  /**
720  * Set shadow map light eye distance scale
721  * @param shadowMapLightEyeDistanceScale shadow map light eye distance scale
722  */
724  this->shadowMapLightEyeDistanceScale = shadowMapLightEyeDistanceScale;
725  }
726 
727  /**
728  * @return shadow map width
729  */
730  inline static int32_t getShadowMapWidth() {
731  return Engine::shadowMapWidth;
732  }
733 
734  /**
735  * @return shadow map height
736  */
737  inline static int32_t getShadowMapHeight() {
739  }
740 
741  /**
742  * @return shadow map render look ups
743  */
744  inline static int32_t getShadowMapRenderLookUps() {
746  }
747 
748  /**
749  * Set shadow map size
750  * @param width width
751  * @param height height
752  */
753  inline static void setShadowMapSize(int32_t width, int32_t height) {
756  }
757 
758  /**
759  * Set shadowmap look ups for each pixel when rendering
760  * @param shadow map render look ups
761  */
762  inline static void setShadowMapRenderLookUps(int32_t shadowMapRenderLookUps) {
764  }
765 
766  /**
767  * @return environment mapping width
768  */
769  inline static int32_t getEnvironmentMappingWidth() {
771  }
772 
773  /**
774  * @return environment mapping height
775  */
776  inline static int32_t getEnvironmentMappingHeight() {
778  }
779 
780  /**
781  * Set environment mapping size
782  * @param width width
783  * @param height height
784  */
785  inline static void setEnvironmentMappingSize(int32_t width, int32_t height) {
788  }
789 
790  /**
791  * @return distance of animated object including skinned objects from which animation computing will be computed only every second frame
792  */
795  }
796 
797  /**
798  * Set distance of animated object including skinned objects from camera which animation computation will be computed only every second frame
799  * @param animationComputationReduction1Distance distance
800  */
803  }
804 
805  /**
806  * @return distance of animated object including skinned objects from which animation computation will be computed only every forth frame
807  */
810  }
811 
812  /**
813  * Set distance of animated object including skinned objects from camera which animation computation will be computed only every forth frame
814  * @param animationComputationReduction2Distance distance
815  */
818  }
819 
820  /**
821  * @return unique shader id
822  */
823  static uint8_t getUniqueShaderId(const string& shaderId) {
824  auto uniqueShaderIdIt = uniqueShaderIds.find(shaderId);
825  if (uniqueShaderIdIt == uniqueShaderIds.end()) {
826  auto uniqueShaderId = uniqueShaderIds.size() + 1;
827  uniqueShaderIds[shaderId] = uniqueShaderId;
828  return uniqueShaderId;
829  }
830  return uniqueShaderIdIt->second;
831  }
832 
833  /**
834  * Returns registered shaders for given type
835  * @param type type
836  */
837  inline static const vector<string> getRegisteredShader(ShaderType type, bool sort = true) {
838  vector<string> result;
839  for (const auto& shader: shaders) {
840  if (shader.internal == true) continue;
841  if (shader.type == type) {
842  result.push_back(shader.id);
843  }
844  }
845  if (sort == true) std::sort(result.begin(), result.end());
846  return result;
847  }
848 
849  /**
850  * Register shader
851  * @param type shader type
852  * @param shaderId shader id
853  * @param parameterDefaults parameter defaults
854  * @param internal internal usage only
855  */
856  inline static void registerShader(ShaderType type, const string& shaderId, const vector<Shader::ParameterDefaults>& parameterDefaults = {}, bool internal = false) {
857  if (shadersById.find(shaderId) != shadersById.end()) {
858  Console::println("Engine::registerShader(): Shader already registered: " + shaderId);
859  return;
860  }
861  shaders.push_back(
862  {
863  .internal = internal,
864  .type = type,
865  .id = shaderId,
866  .parameterDefaults = parameterDefaults,
867  .parameterDefaultsByName = {}
868  }
869  );
870  for (const auto& shaderParameterDefaults: shaders.back().parameterDefaults) {
871  shaders.back().parameterDefaultsByName[shaderParameterDefaults.name] = &shaderParameterDefaults;
872  }
873  //
874  shadersById[shaders.back().id] = &shaders.back();
875  }
876 
877  /**
878  * Returns parameter defaults of shader with given id
879  * @param shaderId shader id
880  * @return shader parameter defaults
881  */
882  inline static const vector<Shader::ParameterDefaults>* getShaderParameterDefaults(const string& shaderId) {
883  auto shaderIt = shadersById.find(shaderId);
884  if (shaderIt == shadersById.end()) {
885  Console::println("Engine::getShaderParameterDefaults(): No registered shader: " + shaderId);
886  return nullptr;
887  }
888  return &shaderIt->second->parameterDefaults;
889  }
890 
891  /**
892  * Returns shader parameter names of shader with given id
893  * @param shaderId shader id
894  * @return shader parameter names
895  */
896  inline static const vector<string> getShaderParameterNames(const string& shaderId) {
897  vector<string> shaderParameterNames;
898  auto shaderIt = shadersById.find(shaderId);
899  if (shaderIt == shadersById.end()) {
900  Console::println("Engine::getShaderParameterNames(): No registered shader: " + shaderId);
901  return shaderParameterNames;
902  }
903  for (const auto& shaderParameterName: shaderIt->second->parameterDefaults) {
904  shaderParameterNames.push_back(shaderParameterName.name);
905  }
906  return shaderParameterNames;
907  }
908 
909  /**
910  * Returns shader parameter default value for given shader id and parameter name
911  * @param shaderId shader id
912  * @param parameterName parameter name
913  * @return shader parameter
914  */
915  inline static const Shader::ParameterDefaults* getDefaultShaderParameter(const string& shaderId, const string& parameterName) {
916  // try to find registered shader
917  auto shaderIt = shadersById.find(shaderId);
918  if (shaderIt == shadersById.end()) {
919  // not found, return empty shader parameter
920  Console::println("Engine::getDefaultShaderParameter(): no shader registered with id: " + shaderId);
921  return nullptr;
922  }
923  // fetch from defaults
924  const auto shader = shaderIt->second;
925  auto shaderParameterIt = shader->parameterDefaultsByName.find(parameterName);
926  if (shaderParameterIt == shader->parameterDefaultsByName.end()) {
927  // not found
928  Console::println("Engine::getDefaultShaderParameter(): no default for shader registered with id: " + shaderId + ", and parameter name: " + parameterName);
929  return nullptr;
930  }
931  // done
932  return shaderParameterIt->second;
933  }
934 
935  /**
936  * Returns shader parameter for given shader id and parameter name, if the value does not exist, the default will be returned
937  * @param shaderId shader id
938  * @param parameterName parameter name
939  * @return shader parameter
940  */
941  inline const ShaderParameter getShaderParameter(const string& shaderId, const string& parameterName) {
942  // try to find shader in engine shader parameters
943  auto shaderParameterIt = shaderParameters.find(shaderId);
944  if (shaderParameterIt == shaderParameters.end()) {
945  // not found, use default shader parameter
946  auto defaultShaderParameter = getDefaultShaderParameter(shaderId, parameterName);
947  if (defaultShaderParameter == nullptr) return ShaderParameter();
948  return defaultShaderParameter->value;
949  }
950  //
951  const auto& shaderParameterMap = shaderParameterIt->second;
952  //
953  auto shaderParameterParameterIt = shaderParameterMap.find(parameterName);
954  if (shaderParameterParameterIt == shaderParameterMap.end()) {
955  // not found, use default shader parameter
956  auto defaultShaderParameter = getDefaultShaderParameter(shaderId, parameterName);
957  if (defaultShaderParameter == nullptr) return ShaderParameter();
958  return defaultShaderParameter->value;
959  }
960  // done
961  return shaderParameterParameterIt->second;
962  }
963 
964  /**
965  * Set shader parameter for given shader id and parameter name
966  * @param shaderId shader id
967  * @param parameterName parameter name
968  * @param paraemterValue parameter value
969  */
970  inline void setShaderParameter(const string& shaderId, const string& parameterName, const ShaderParameter& parameterValue) {
971  auto currentShaderParameter = getShaderParameter(shaderId, parameterName);
972  if (currentShaderParameter.getType() == ShaderParameter::TYPE_NONE) {
973  Console::println("Engine::setShaderParameter(): no parameter for shader registered with id: " + shaderId + ", and parameter name: " + parameterName);
974  return;
975  }
976  if (currentShaderParameter.getType() != parameterValue.getType()) {
977  Console::println("Engine::setShaderParameter(): parameter type mismatch for shader registered with id: " + shaderId + ", and parameter name: " + parameterName);
978  }
979  shaderParameters[shaderId][parameterName] = parameterValue;
980  }
981 
982  /**
983  * Load textures
984  * @param pathName path name
985  */
986  void loadTextures(const string& pathName);
987 
988  /**
989  * Creates an offscreen rendering instance
990  * Note:
991  * - the root engine must have been initialized before
992  * - the created offscreen engine must not be initialized
993  * @param width width
994  * @param height height
995  * @param enableShadowMapping enable shadow mapping
996  * @param enableDepthBuffer enable depth buffer
997  * @param enableDepthBuffer enable geometry buffer
998  * @return off screen engine
999  */
1000  static Engine* createOffScreenInstance(int32_t width, int32_t height, bool enableShadowMapping, bool enableDepthBuffer, bool enableGeometryBuffer);
1001 
1002  /**
1003  * @return graphics vendor
1004  */
1005  const string getGraphicsVendor();
1006 
1007  /**
1008  * @return graphics renderer
1009  */
1010  const string getGraphicsRenderer();
1011 
1012  /**
1013  * @return graphics renderer type
1014  */
1015  inline Renderer::RendererType getGraphicsRendererType() {
1016  return renderer->getRendererType();
1017  }
1018 
1019  /**
1020  * @return if initialized and ready to be used
1021  */
1022  inline bool isInitialized() {
1023  return initialized;
1024  }
1025 
1026  /**
1027  * @return width
1028  */
1029  inline int32_t getWidth() {
1030  return width;
1031  }
1032 
1033  /**
1034  * @return height
1035  */
1036  inline int32_t getHeight() {
1037  return height;
1038  }
1039 
1040  /**
1041  * @return scaled width or -1 if not in use
1042  */
1043  inline int32_t getScaledWidth() {
1044  return scaledWidth;
1045  }
1046 
1047  /**
1048  * @return scaled height -1 if not in use
1049  */
1050  inline int32_t getScaledHeight() {
1051  return scaledHeight;
1052  }
1053 
1054  /**
1055  * @return GUI
1056  */
1057  inline GUI* getGUI() {
1058  return gui.get();
1059  }
1060 
1061  /**
1062  * @return Timing
1063  */
1064  inline Timing* getTiming() {
1065  return timing.get();
1066  }
1067 
1068  /**
1069  * @return Camera
1070  */
1071  inline Camera* getCamera() {
1072  return camera.get();
1073  }
1074 
1075  /**
1076  * @return GIZMO Camera
1077  */
1079  return gizmoCamera.get();
1080  }
1081 
1082  /**
1083  * @return partition
1084  */
1086  return partition.get();
1087  }
1088 
1089  /**
1090  * Set partition
1091  * @param partition partition
1092  */
1094 
1095  /**
1096  * @return frame buffer or nullptr
1097  */
1099  return frameBuffer.get();;
1100  }
1101 
1102  /**
1103  * @return geometry buffer or nullptr
1104  */
1106  return geometryBuffer.get();;
1107  }
1108 
1109  /**
1110  * @return sky shader enabled
1111  */
1112  inline bool isSkyShaderEnabled() {
1113  return skyShaderEnabled;
1114  }
1115 
1116  /**
1117  * Set sky shader enabled
1118  * @param skyShaderEnabled sky shader enabled
1119  */
1121  this->skyShaderEnabled = skyShaderEnabled;
1122  }
1123 
1124  /**
1125  * @return lights iterator
1126  */
1128  return UniquePtrSequenceIterator<Light>(&(*lights.begin()), &(*lights.end()));
1129  }
1130 
1131  /**
1132  * @return count of lights
1133  */
1134  inline int32_t getLightCount() {
1135  return lights.size();
1136  }
1137 
1138  /**
1139  * Returns light at idx (0 <= idx < 8)
1140  * @param idx idx
1141  * @return Light
1142  */
1143  inline Light* getLightAt(int32_t idx) {
1144  if (idx < 0 || idx >= lights.size()) return nullptr;
1145  return lights[idx].get();
1146  }
1147 
1148  /**
1149  * @return scene / background color
1150  */
1151  inline const Color4& getSceneColor() const {
1152  return sceneColor;
1153  }
1154 
1155  /**
1156  * Set scene color
1157  * @param sceneColor scene color
1158  */
1159  inline void setSceneColor(const Color4& sceneColor) {
1160  this->sceneColor = sceneColor;
1161  }
1162 
1163  /**
1164  * @return entity count
1165  */
1166  inline int32_t getEntityCount() {
1167  return entitiesById.size();
1168  }
1169 
1170  /**
1171  * Returns a entity by given id
1172  * @param id id
1173  * @return entity or nullptr
1174  */
1175  inline Entity* getEntity(const string& id) {
1176  auto entityByIdIt = entitiesById.find(id);
1177  if (entityByIdIt != entitiesById.end()) {
1178  return entityByIdIt->second;
1179  }
1180  return nullptr;
1181  }
1182 
1183  /**
1184  * Adds an entity by id
1185  * @param entity object
1186  */
1187  void addEntity(Entity* entity);
1188 
1189  /**
1190  * Removes an entity
1191  * @param id id
1192  * @return if entity was found and removed
1193  */
1194  bool removeEntity(const string& id);
1195 
1196  /**
1197  * Removes all entities and caches
1198  */
1199  void reset();
1200 
1201  /**
1202  * Initialize render engine
1203  */
1204  void initialize();
1205 
1206  /**
1207  * Reshape
1208  * @param width width
1209  * @param height height
1210  */
1211  void reshape(int32_t width, int32_t height);
1212 
1213  /**
1214  * Scale which applies to main engine only
1215  * @param width width
1216  * @param height height
1217  */
1218  void scale(int32_t width, int32_t height);
1219 
1220  /**
1221  * Disable scaling, which applies to main engine only
1222  */
1223  void unscale();
1224 
1225  /**
1226  * Render scaled main engine to screen
1227  */
1228  void renderToScreen();
1229 
1230  /**
1231  * Renders the scene
1232  */
1233  void display();
1234 
1235  /**
1236  * Compute gizmo coordinate from mouse position and z value
1237  * @param mouseX mouse x
1238  * @param mouseY mouse y
1239  * @param z z
1240  * @return gizmo coordinate
1241  */
1242  inline Vector3 computeGizmoCoordinateByMousePosition(int32_t mouseX, int32_t mouseY, float z) {
1243  return computeWorldCoordinateByMousePosition(mouseX, mouseY, z, gizmoCamera.get());
1244  }
1245 
1246  /**
1247  * Compute world coordinate from mouse position and z value
1248  * @param mouseX mouse x
1249  * @param mouseY mouse y
1250  * @param z z
1251  * @return world coordinate
1252  */
1253  inline Vector3 computeWorldCoordinateByMousePosition(int32_t mouseX, int32_t mouseY, float z) {
1254  return computeWorldCoordinateByMousePosition(mouseX, mouseY, z, camera.get());
1255  }
1256 
1257  /**
1258  * Compute world coordinate from mouse position
1259  * Note: this does not work with GLES2 as reading from depth buffer is not available
1260  * @param mouseX mouse x
1261  * @param mouseY mouse y
1262  * @return coordinate
1263  */
1264  Vector3 computeWorldCoordinateByMousePosition(int32_t mouseX, int32_t mouseY);
1265 
1266  /**
1267  * Retrieves entity by mouse position
1268  * @param mouseX mouse x
1269  * @param mouseY mouse y
1270  * @param filter filter
1271  * @param objectNode pointer to store node of object to if appliable
1272  * @param particleSystemEntity pointer to store sub particle system entity if having a particle system group
1273  * @return entity or nullptr
1274  */
1275  inline Entity* getEntityByMousePosition(int32_t mouseX, int32_t mouseY, EntityPickingFilter* filter = nullptr, Node** objectNode = nullptr, ParticleSystem** particleSystemEntity = nullptr) {
1276  return
1279  false,
1280  mouseX,
1281  mouseY,
1282  filter,
1283  objectNode,
1284  particleSystemEntity
1285  );
1286  }
1287 
1288  /**
1289  * Retrieves entity by mouse position with contact point
1290  * @param mouseX mouse x
1291  * @param mouseY mouse y
1292  * @param contactPoint world coordinate of contact point
1293  * @param filter filter
1294  * @param objectNode pointer to store node of object to if appliable
1295  * @param particleSystemEntity pointer to store sub particle system entity if having a particle system group
1296  * @return entity or nullptr
1297  */
1298  Entity* getEntityByMousePosition(int32_t mouseX, int32_t mouseY, Vector3& contactPoint, EntityPickingFilter* filter = nullptr, Node** objectNode = nullptr, ParticleSystem** particleSystemEntity = nullptr);
1299 
1300  /**
1301  * Does a ray casting of visible 3d object based entities
1302  * @param startPoint start point
1303  * @param endPoint end point
1304  * @param contactPoint world coordinate of contact point
1305  * @param filter filter
1306  * @return entity or nullptr
1307  */
1309  const Vector3& startPoint,
1310  const Vector3& endPoint,
1311  Vector3& contactPoint,
1312  EntityPickingFilter* filter = nullptr
1313  ) {
1314  return
1315  doRayCasting(
1317  false,
1318  startPoint,
1319  endPoint,
1320  contactPoint,
1321  filter
1322  );
1323  }
1324 
1325  /**
1326  * Retrieves object by mouse position
1327  * @param mouseX mouse x
1328  * @param mouseY mouse y
1329  * @param filter filter
1330  * @return entity or nullptr
1331  */
1332  Entity* getEntityContactPointByMousePosition(int32_t mouseX, int32_t mouseY, EntityPickingFilter* filter);
1333 
1334  /**
1335  * Convert screen coordinate by world coordinate
1336  * @param worldCoordinate world woordinate
1337  * @param screenCoordinate screen coordinate
1338  * @param width optional render target width
1339  * @param height optional render target height
1340  * @returns if world coordinate is within frustum
1341  */
1342  bool computeScreenCoordinateByWorldCoordinate(const Vector3& worldCoordinate, Vector2& screenCoordinate, int width = -1, int height = -1);
1343 
1344  /**
1345  * Shutdown the engine
1346  */
1347  void dispose();
1348 
1349  /**
1350  * Creates a PNG file from current screen(
1351  * This does not seem to work with GLES2 and offscreen engines
1352  * @param pathName path name
1353  * @param fileName file name
1354  * @param removeAlphaChannel remove alpha channel
1355  * @return success
1356  */
1357  bool makeScreenshot(const string& pathName, const string& fileName, bool removeAlphaChannel = true);
1358 
1359  /**
1360  * Creates a PNG file from current screen into a data vector
1361  * This does not seem to work with GLES2 and offscreen engines
1362  * @param pngData png data
1363  * @return success
1364  */
1365  bool makeScreenshot(vector<uint8_t>& pngData);
1366 
1367  /**
1368  * Clear post processing programs
1369  */
1371 
1372  /**
1373  * Add post processing program
1374  * @param programId program id
1375  */
1376  void addPostProcessingProgram(const string& programId);
1377 
1378  /**
1379  * @return renderer statistics
1380  */
1381  inline Renderer::Renderer_Statistics getRendererStatistics() {
1382  return renderer->getStatistics();
1383  }
1384 
1385  /**
1386  * Print registered shaders and it default parameters to console
1387  */
1388  void dumpShaders();
1389 
1390  /**
1391  * Dump entities
1392  */
1393  void dumpEntities();
1394 
1395  /**
1396  * Add action to action queue to be executed before next engine update
1397  * @param action action
1398  */
1399  inline void enqueueAction(Action* action) {
1400  actions.push_back(unique_ptr<Action>(action));
1401  }
1402 
1403 private:
1404 
1405  /**
1406  * Dump entity hierarchy
1407  * @param entityHierarchy entity hierarchy
1408  * @param indent indent
1409  * @param parentNodeId parent node id
1410  */
1411  void dumpEntityHierarchy(EntityHierarchy* entityHierarchy, int indent, const string& parentNodeId);
1412 
1413  /**
1414  * Compute world coordinate from mouse position and z value
1415  * @param mouseX mouse x
1416  * @param mouseY mouse y
1417  * @param z z
1418  * @param camera camera or engine camera
1419  * @return world coordinate
1420  */
1421  Vector3 computeWorldCoordinateByMousePosition(int32_t mouseX, int32_t mouseY, float z, Camera* camera);
1422 
1423  /**
1424  * Compute world coordinate from mouse position
1425  * TODO: this does not work with GLES2
1426  * @param mouseX mouse x
1427  * @param mouseY mouse y
1428  * @param camera camera or engine camera
1429  * @return world coordinate
1430  */
1431  Vector3 computeWorldCoordinateByMousePosition(int32_t mouseX, int32_t mouseY, Camera* camera);
1432 
1433  /**
1434  * Retrieves entity by mouse position
1435  * @param decomposedEntities decomposed entities
1436  * @param forcePicking override picking to be always enabled
1437  * @param mouseX mouse x
1438  * @param mouseY mouse y
1439  * @param filter filter
1440  * @param objectNode pointer to store node of Object to if appliable
1441  * @param particleSystemEntity pointer to store sub particle system entity if having a particle system group
1442  * @return entity or nullptr
1443  */
1445  DecomposedEntities& decomposedEntities,
1446  bool forcePicking,
1447  int32_t mouseX,
1448  int32_t mouseY,
1449  EntityPickingFilter* filter = nullptr,
1450  Node** objectNode = nullptr,
1451  ParticleSystem** particleSystemEntity = nullptr
1452  );
1453 
1454  /**
1455  * Does a ray casting of visible 3d object based entities
1456  * @param decomposedEntities decomposed entities
1457  * @param forcePicking override picking to be always enabled
1458  * @param startPoint start point
1459  * @param endPoint end point
1460  * @param contactPoint world coordinate of contact point
1461  * @param filter filter
1462  * @return entity or nullptr
1463  */
1465  DecomposedEntities& decomposedEntities,
1466  bool forcePicking,
1467  const Vector3& startPoint,
1468  const Vector3& endPoint,
1469  Vector3& contactPoint,
1470  EntityPickingFilter* filter = nullptr
1471  );
1472 
1473  /**
1474  * Removes a entity from internal lists, those entities can also be sub entities from entity hierarchy or particle system groups and such
1475  * @param entity entity
1476  */
1477  void deregisterEntity(Entity* entity);
1478 
1479  /**
1480  * Adds a entity to internal lists, those entities can also be sub entities from entity hierarchy or particle system groups and such
1481  * @param entity entity
1482  */
1483  void registerEntity(Entity* entity);
1484 
1485  /**
1486  * Updates registration of engine by performing deregisterEntity() and registerEntity()
1487  * @param entity entity
1488  */
1489  inline void updateEntityRegistration(Entity* entity) {
1490  deregisterEntity(entity);
1491  registerEntity(entity);
1492  }
1493 
1494  /**
1495  * Do post processing
1496  * @param renderPass render pass
1497  * @param postProcessingFrameBuffers frame buffers to swap, input needs to live in postProcessingFrameBuffers[0]
1498  * @param targetFrameBuffer target frame buffer
1499  */
1500  void doPostProcessing(PostProcessingProgram::RenderPass renderPass, const array<FrameBuffer*, 2> postProcessingFrameBuffers, FrameBuffer* targetFrameBuffer);
1501 
1502  /**
1503  * Do a render/effect pass
1504  * @param renderFrameBuffer render frame buffer
1505  * @param renderGeometryBuffer render geometry buffer
1506  * @param rendererCamera renderer camera
1507  * @param visibleDecomposedEntities visible decomposed entities
1508  * @param effectPass effect pass
1509  * @param renderPassMask render pass mask
1510  * @param shaderPrefix shader prefix
1511  * @param applyShadowMapping if to apply shadow mapping
1512  * @param applyPostProcessing if to apply post processing
1513  * @param doRenderLightSource do render light source
1514  * @param doRenderParticleSystems if to render particle systems
1515  * @param renderTypes render types
1516  * @param skyShaderEnabled sky shader enabled
1517  */
1518  void render(FrameBuffer* renderFrameBuffer, GeometryBuffer* renderGeometryBuffer, Camera* rendererCamera, DecomposedEntities& visibleDecomposedEntities, int32_t effectPass, int32_t renderPassMask, const string& shaderPrefix, bool applyShadowMapping, bool applyPostProcessing, bool doRenderLightSource, bool doRenderParticleSystems, int32_t renderTypes, bool skyShaderEnabled);
1519 
1520  /**
1521  * Render light sources
1522  * @param width render target width
1523  * @param height render target height
1524  * @return if light source is visible
1525  */
1526  bool renderLightSources(int width, int height);
1527 
1528  /**
1529  * Remove entity from decomposed entities
1530  * @param decomposedEntities decomposed entities
1531  * @param entity entity
1532  */
1533  void removeFromDecomposedEntities(DecomposedEntities& decomposedEntities, Entity* entity);
1534 
1535  /**
1536  * Remove entity
1537  * @param entity entity
1538  */
1539  void removeEntityFromLists(Entity* entity);
1540 
1541  /**
1542  * Register model
1543  * @param model model
1544  */
1545  int registerModel(Model* model) {
1546  auto objectUniqueModelIdMappingIt = objectUniqueModelIdMapping.find(model);
1547  if (objectUniqueModelIdMappingIt == objectUniqueModelIdMapping.end()) {
1548  // reset
1549  auto uniqueModelId = UNIQUEMODELID_NONE;
1550  // reuse a unique partition id from freeObjectUniqueModelIdIds
1551  if (freeObjectUniqueModelIdIds.empty() == false) {
1552  // yet
1553  uniqueModelId = freeObjectUniqueModelIdIds[freeObjectUniqueModelIdIds.size() - 1];
1555  } else {
1556  // otherwise create a id
1557  uniqueModelId = objectUniqueModelIdMapping.size() + 1;
1558  if (uniqueModelId >= UNIQUEMODELID_MAX) {
1559  Console::println("Engine::registerModel(): too many models: " + to_string(uniqueModelId) + " >= " + to_string(UNIQUEMODELID_MAX));
1560  return -1;
1561  }
1562  }
1563  objectUniqueModelIdMapping[model] = {
1564  .id = uniqueModelId,
1565  .count = 1
1566  };
1567  return uniqueModelId;
1568  } else {
1569  auto& uniqueModel = objectUniqueModelIdMappingIt->second;
1570  uniqueModel.count++;
1571  return uniqueModel.id;
1572  }
1573  }
1574 
1575  /**
1576  * Deregister model
1577  * @param model model
1578  * @param uniqueModelId unique model id
1579  */
1580  void deregisterModel(Model* model) {
1581  auto objectUniqueModelIdMappingIt = objectUniqueModelIdMapping.find(model);
1582  if (objectUniqueModelIdMappingIt != objectUniqueModelIdMapping.end()) {
1583  auto& uniqueModel = objectUniqueModelIdMappingIt->second;
1584  uniqueModel.count--;
1585  if (uniqueModel.count == 0) {
1586  freeObjectUniqueModelIdIds.push_back(uniqueModel.id);
1587  objectUniqueModelIdMapping.erase(objectUniqueModelIdMappingIt);
1588  }
1589  }
1590  }
1591 
1592 };
Application base class, please make sure to allocate application on heap to have correct application ...
Definition: Application.h:41
Color 4 definition class.
Definition: Color4.h:18
Decal entity to be used with engine class.
Definition: Decal.h:36
EngineThreadQueueElement * instantiate() override
Instantiate a transparent render face.
Definition: Engine.h:421
array< vector< Object * >, Engine::UNIQUEMODELID_MAX > objectsByModels
Definition: Engine.h:370
TransparentRenderFacesPool * getTransparentRenderFacesPool()
Definition: Engine.h:389
unique_ptr< TransparentRenderFacesPool > transparentRenderFacesPool
Definition: Engine.h:369
Queue< EngineThreadQueueElement > * queue
Definition: Engine.h:368
void resetProcessedElements()
Reset processed element count.
Definition: Engine.h:403
EngineThread(int idx, Queue< EngineThreadQueueElement > *queue)
Constructor.
Definition: Engine.cpp:213
Engine main class.
Definition: Engine.h:131
static void setShadowMapRenderLookUps(int32_t shadowMapRenderLookUps)
Set shadowmap look ups for each pixel when rendering.
Definition: Engine.h:762
static STATIC_DLL_IMPEXT Engine * currentEngine
Definition: Engine.h:201
bool isInitialized()
Definition: Engine.h:1022
static STATIC_DLL_IMPEXT unique_ptr< PostProcessingShader > postProcessingShader
Definition: Engine.h:226
bool renderLightSources(int width, int height)
Render light sources.
Definition: Engine.cpp:2624
unique_ptr< FrameBuffer > frameBuffer
Definition: Engine.h:294
void dumpShaders()
Print registered shaders and it default parameters to console.
Definition: Engine.cpp:2644
bool removeEntity(const string &id)
Removes an entity.
Definition: Engine.cpp:502
array< unique_ptr< FrameBuffer >, EFFECTPASS_COUNT - 1 > effectPassFrameBuffers
Definition: Engine.h:299
static STATIC_DLL_IMPEXT unique_ptr< GUIShader > guiShader
Definition: Engine.h:220
Renderer::RendererType getGraphicsRendererType()
Definition: Engine.h:1015
static STATIC_DLL_IMPEXT Renderer * renderer
Definition: Engine.h:205
static STATIC_DLL_IMPEXT unique_ptr< DeferredLightingRenderShader > deferredLightingRenderShader
Definition: Engine.h:223
static STATIC_DLL_IMPEXT int32_t environmentMappingWidth
Definition: Engine.h:234
unique_ptr< Partition > partition
Definition: Engine.h:289
static GUIShader * getGUIShader()
Definition: Engine.h:476
Vector3 computeWorldCoordinateByMousePosition(int32_t mouseX, int32_t mouseY, Camera *camera)
Compute world coordinate from mouse position TODO: this does not work with GLES2.
TextureAtlas & getPointParticleSystemTextureAtlas()
Definition: Engine.h:518
void initRendering()
Initiates the rendering process updates timing, updates camera.
Definition: Engine.cpp:1078
static STATIC_DLL_IMPEXT int32_t shadowMapHeight
Definition: Engine.h:232
void doPostProcessing(PostProcessingProgram::RenderPass renderPass, const array< FrameBuffer *, 2 > postProcessingFrameBuffers, FrameBuffer *targetFrameBuffer)
Do post processing.
Definition: Engine.cpp:2240
Light * getLightAt(int32_t idx)
Returns light at idx (0 <= idx < 8)
Definition: Engine.h:1143
TextureAtlas decalsTextureAtlas
Definition: Engine.h:329
vector< unique_ptr< Action > > actions
Definition: Engine.h:331
TextureAtlas & getDecalsTextureAtlas()
Definition: Engine.h:525
void reshape(int32_t width, int32_t height)
Reshape.
Definition: Engine.cpp:972
int32_t getLightCount()
Definition: Engine.h:1134
void display()
Renders the scene.
Definition: Engine.cpp:1361
static void setAnimationComputationReduction1Distance(float animationComputationReduction1Distance)
Set distance of animated object including skinned objects from camera which animation computation wil...
Definition: Engine.h:801
ShadowMapping * getShadowMapping()
Definition: Engine.h:448
static STATIC_DLL_IMPEXT unique_ptr< LinesShader > linesShader
Definition: Engine.h:218
TextureAtlas ppsTextureAtlas
Definition: Engine.h:328
void preRenderFunction(vector< Object * > &objects, int threadIdx)
Update vertex buffers and such before rendering.
Definition: Engine.cpp:1087
unique_ptr< FrameBuffer > postProcessingFrameBuffer2
Definition: Engine.h:297
static STATIC_DLL_IMPEXT unique_ptr< GUIRenderer > guiRenderer
Definition: Engine.h:210
void initialize()
Initialize render engine.
Definition: Engine.cpp:733
static const Shader::ParameterDefaults * getDefaultShaderParameter(const string &shaderId, const string &parameterName)
Returns shader parameter default value for given shader id and parameter name.
Definition: Engine.h:915
static Engine * getInstance()
Returns engine instance.
Definition: Engine.h:612
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.
Definition: Engine.cpp:2151
static float getAnimationComputationReduction2Distance()
Definition: Engine.h:808
static STATIC_DLL_IMPEXT int32_t shadowMapRenderLookUps
Definition: Engine.h:233
static STATIC_DLL_IMPEXT int threadCount
Definition: Engine.h:228
static STATIC_DLL_IMPEXT float animationComputationReduction1Distance
Definition: Engine.h:236
static ShadowMapRenderShader * getShadowMapRenderShader()
Definition: Engine.h:663
Vector3 computeGizmoCoordinateByMousePosition(int32_t mouseX, int32_t mouseY, float z)
Compute gizmo coordinate from mouse position and z value.
Definition: Engine.h:1242
static void setEnvironmentMappingSize(int32_t width, int32_t height)
Set environment mapping size.
Definition: Engine.h:785
unique_ptr< FrameBuffer > postProcessingTemporaryFrameBuffer
Definition: Engine.h:298
FrameBuffer * getFrameBuffer()
Definition: Engine.h:1098
EntityRenderer * getEntityRenderer()
Definition: Engine.h:511
GeometryBuffer * getGeometryBuffer()
Definition: Engine.h:1105
Camera * getCamera()
Definition: Engine.h:1071
Entity * getEntityContactPointByMousePosition(int32_t mouseX, int32_t mouseY, EntityPickingFilter *filter)
Retrieves object by mouse position.
int32_t getWidth()
Definition: Engine.h:1029
~Engine()
Destructor.
Definition: Engine.cpp:284
static LightingShader * getLightingShader()
Definition: Engine.h:642
const Color4 & getSceneColor() const
Definition: Engine.h:1151
void setShaderParameter(const string &shaderId, const string &parameterName, const ShaderParameter &parameterValue)
Set shader parameter for given shader id and parameter name.
Definition: Engine.h:970
unique_ptr< GUI > gui
Definition: Engine.h:284
void enqueueAction(Action *action)
Add action to action queue to be executed before next engine update.
Definition: Engine.h:1399
static STATIC_DLL_IMPEXT bool skinningShaderEnabled
Definition: Engine.h:315
unordered_set< Entity * > noFrustumCullingEntities
Definition: Engine.h:307
static FrameBufferRenderShader * getFrameBufferRenderShader()
Definition: Engine.h:490
void decomposeEntityTypes(const vector< Entity * > &entities, DecomposedEntities &decomposedEntities, bool decomposeAllEntities=false)
Decompose entity types.
Definition: Engine.cpp:1227
Vector3 computeWorldCoordinateByMousePosition(int32_t mouseX, int32_t mouseY, float z)
Compute world coordinate from mouse position and z value.
Definition: Engine.h:1253
static STATIC_DLL_IMPEXT int32_t environmentMappingHeight
Definition: Engine.h:235
void setPartition(Partition *partition)
Set partition.
Definition: Engine.cpp:352
static constexpr int UNIQUEMODELID_NONE
Definition: Engine.h:335
unique_ptr< Camera > gizmoCamera
Definition: Engine.h:287
void addPostProcessingProgram(const string &programId)
Add post processing program.
Definition: Engine.cpp:2235
static STATIC_DLL_IMPEXT AnimationProcessingTarget animationProcessingTarget
Definition: Engine.h:212
void doneGUIMode()
Set up GUI mode rendering.
Definition: Engine.cpp:2142
Entity * doRayCasting(const Vector3 &startPoint, const Vector3 &endPoint, Vector3 &contactPoint, EntityPickingFilter *filter=nullptr)
Does a ray casting of visible 3d object based entities.
Definition: Engine.h:1308
unique_ptr< EntityRenderer > entityRenderer
Definition: Engine.h:313
void initGUIMode()
Set up GUI mode rendering.
Definition: Engine.cpp:2130
static void setAnimationBlendingTime(float animationBlendingTime)
Set animation blending time.
Definition: Engine.h:708
static STATIC_DLL_IMPEXT unique_ptr< LightingShader > lightingShader
Definition: Engine.h:216
void decomposeEntityType(Entity *entity, DecomposedEntities &decomposedEntities, bool decomposeAllEntities=false)
Decompose entity type.
Definition: Engine.cpp:1095
void updateEntityRegistration(Entity *entity)
Updates registration of engine by performing deregisterEntity() and registerEntity()
Definition: Engine.h:1489
Renderer::Renderer_Statistics getRendererStatistics()
Definition: Engine.h:1381
void setSkyShaderEnabled(bool skyShaderEnabled)
Set sky shader enabled.
Definition: Engine.h:1120
void computeAnimationsFunction(vector< Object * > &objects, int threadIdx)
Computes animations.
Definition: Engine.cpp:1091
static STATIC_DLL_IMPEXT unique_ptr< BRDFLUTShader > brdfLUTShader
Definition: Engine.h:221
unique_ptr< FrameBuffer > postProcessingFrameBuffer1
Definition: Engine.h:296
void removeFromDecomposedEntities(DecomposedEntities &decomposedEntities, Entity *entity)
Remove entity from decomposed entities.
Definition: Engine.cpp:534
static STATIC_DLL_IMPEXT unique_ptr< ParticlesShader > particlesShader
Definition: Engine.h:217
UniquePtrSequenceIterator< Light > getLights()
Definition: Engine.h:1127
static STATIC_DLL_IMPEXT float animationComputationReduction2Distance
Definition: Engine.h:237
void deregisterModel(Model *model)
Deregister model.
Definition: Engine.h:1580
static Renderer * getRenderer()
Definition: Engine.h:434
@ EFFECTPASS_LIGHTSCATTERING
Definition: Engine.h:186
static ParticlesShader * getParticlesShader()
Definition: Engine.h:455
static Engine * createOffScreenInstance(int32_t width, int32_t height, bool enableShadowMapping, bool enableDepthBuffer, bool enableGeometryBuffer)
Creates an offscreen rendering instance Note:
Definition: Engine.cpp:297
static void shutdown()
Shuts down main engine.
Definition: Engine.cpp:263
int32_t getHeight()
Definition: Engine.h:1036
vector< int > freeObjectUniqueModelIdIds
Definition: Engine.h:341
Partition * getPartition()
Definition: Engine.h:1085
static PostProcessingShader * getPostProcessingShader()
Definition: Engine.h:649
static STATIC_DLL_IMPEXT unique_ptr< ShadowMapRenderShader > shadowMappingShaderRender
Definition: Engine.h:215
void scale(int32_t width, int32_t height)
Scale which applies to main engine only.
Definition: Engine.cpp:1030
static TextureManager * getTextureManager()
Definition: Engine.h:627
static STATIC_DLL_IMPEXT unordered_map< string, uint8_t > uniqueShaderIds
Definition: Engine.h:278
static constexpr int ENGINETHREADSQUEUE_COMPUTE_DISPATCH_COUNT
Definition: Engine.h:191
static STATIC_DLL_IMPEXT unique_ptr< ShadowMapCreationShader > shadowMappingShaderPre
Definition: Engine.h:214
bool shadowMappingEnabled
Definition: Engine.h:317
static int32_t getShadowMapWidth()
Definition: Engine.h:730
static STATIC_DLL_IMPEXT unique_ptr< Queue< EngineThreadQueueElement > > engineThreadsQueue
Definition: Engine.h:428
bool isSkyShaderEnabled()
Definition: Engine.h:1112
void dumpEntities()
Dump entities.
Definition: Engine.cpp:2904
int32_t getEntityCount()
Definition: Engine.h:1166
Engine()
Private constructor.
Definition: Engine.cpp:269
void renderToScreen()
Render scaled main engine to screen.
Definition: Engine.cpp:1053
void setShadowMapLightEyeDistanceScale(float shadowMapLightEyeDistanceScale)
Set shadow map light eye distance scale.
Definition: Engine.h:723
const string getGraphicsRenderer()
Definition: Engine.cpp:348
array< bool, EFFECTPASS_COUNT - 1 > effectPassSkip
Definition: Engine.h:300
static STATIC_DLL_IMPEXT list< Shader > shaders
Definition: Engine.h:254
static BRDFLUTShader * getBRDFLUTShader()
Definition: Engine.h:483
static void setAnimationComputationReduction2Distance(float animationComputationReduction2Distance)
Set distance of animated object including skinned objects from camera which animation computation wil...
Definition: Engine.h:816
static int32_t getShadowMapHeight()
Definition: Engine.h:737
static void setThreadCount(int threadCount)
Set engine thread count.
Definition: Engine.h:678
unordered_set< Entity * > requirePreRenderEntities
Definition: Engine.h:308
static SkyRenderShader * getSkyRenderShader()
Definition: Engine.h:504
static const vector< string > getRegisteredShader(ShaderType type, bool sort=true)
Returns registered shaders for given type.
Definition: Engine.h:837
unordered_map< string, Entity * > entitiesById
Definition: Engine.h:304
void addEntity(Entity *entity)
Adds an entity by id.
Definition: Engine.cpp:357
unordered_set< Entity * > requireComputeAnimationEntities
Definition: Engine.h:309
const ShaderParameter getShaderParameter(const string &shaderId, const string &parameterName)
Returns shader parameter for given shader id and parameter name, if the value does not exist,...
Definition: Engine.h:941
bool computeScreenCoordinateByWorldCoordinate(const Vector3 &worldCoordinate, Vector2 &screenCoordinate, int width=-1, int height=-1)
Convert screen coordinate by world coordinate.
Definition: Engine.cpp:2058
static STATIC_DLL_IMPEXT unique_ptr< TextureManager > textureManager
Definition: Engine.h:207
unique_ptr< Timing > timing
Definition: Engine.h:285
static float getAnimationComputationReduction1Distance()
Definition: Engine.h:793
static constexpr int UNIQUEMODELID_MAX
Definition: Engine.h:334
static STATIC_DLL_IMPEXT unique_ptr< SkyRenderShader > skyRenderShader
Definition: Engine.h:224
static STATIC_DLL_IMPEXT Engine * instance
Definition: Engine.h:204
static VBOManager * getVBOManager()
Definition: Engine.h:635
static STATIC_DLL_IMPEXT unique_ptr< MeshManager > meshManager
Definition: Engine.h:209
vector< string > postProcessingPrograms
Definition: Engine.h:320
void resetPostProcessingPrograms()
Clear post processing programs.
Definition: Engine.cpp:2231
void deregisterEntity(Entity *entity)
Removes a entity from internal lists, those entities can also be sub entities from entity hierarchy o...
Definition: Engine.cpp:382
void dispose()
Shutdown the engine.
Definition: Engine.cpp:2071
void dumpEntityHierarchy(EntityHierarchy *entityHierarchy, int indent, const string &parentNodeId)
Dump entity hierarchy.
Definition: Engine.cpp:2850
static STATIC_DLL_IMPEXT EngineThreadQueueElementPool engineThreadQueueElementPool
Definition: Engine.h:429
static int32_t getShadowMapRenderLookUps()
Definition: Engine.h:744
unique_ptr< ShadowMapping > shadowMapping
Definition: Engine.h:301
static STATIC_DLL_IMPEXT unique_ptr< FrameBufferRenderShader > frameBufferRenderShader
Definition: Engine.h:222
Entity * getEntity(const string &id)
Returns a entity by given id.
Definition: Engine.h:1175
unordered_map< Model *, UniqueModelId > objectUniqueModelIdMapping
Definition: Engine.h:340
static int getThreadCount()
Definition: Engine.h:670
static void set4K(bool have4K)
Set if having 4k.
Definition: Engine.h:693
float shadowMapLightEyeDistanceScale
Definition: Engine.h:302
static STATIC_DLL_IMPEXT unique_ptr< Texture2DRenderShader > texture2DRenderShader
Definition: Engine.h:227
float getShadowMapLightEyeDistanceScale()
Definition: Engine.h:715
static DeferredLightingRenderShader * getDeferredLightingRenderShader()
Definition: Engine.h:497
static void registerShader(ShaderType type, const string &shaderId, const vector< Shader::ParameterDefaults > &parameterDefaults={}, bool internal=false)
Register shader.
Definition: Engine.h:856
static STATIC_DLL_IMPEXT float animationBlendingTime
Definition: Engine.h:230
const string getGraphicsVendor()
Definition: Engine.cpp:344
static STATIC_DLL_IMPEXT bool have4K
Definition: Engine.h:229
void unscale()
Disable scaling, which applies to main engine only.
Definition: Engine.cpp:1044
static void setShadowMapSize(int32_t width, int32_t height)
Set shadow map size.
Definition: Engine.h:753
unordered_set< Entity * > autoEmitParticleSystemEntities
Definition: Engine.h:306
unique_ptr< GeometryBuffer > geometryBuffer
Definition: Engine.h:293
void reset()
Removes all entities and caches.
Definition: Engine.cpp:716
unique_ptr< Camera > camera
Definition: Engine.h:286
static STATIC_DLL_IMPEXT unique_ptr< VBOManager > vboManager
Definition: Engine.h:208
static float getAnimationBlendingTime()
Definition: Engine.h:700
int32_t getScaledWidth()
Definition: Engine.h:1043
static int32_t getEnvironmentMappingWidth()
Definition: Engine.h:769
static STATIC_DLL_IMPEXT unique_ptr< PostProcessing > postProcessing
Definition: Engine.h:225
void setSceneColor(const Color4 &sceneColor)
Set scene color.
Definition: Engine.h:1159
static STATIC_DLL_IMPEXT vector< unique_ptr< EngineThread > > engineThreads
Definition: Engine.h:427
Entity * getEntityByMousePosition(int32_t mouseX, int32_t mouseY, EntityPickingFilter *filter=nullptr, Node **objectNode=nullptr, ParticleSystem **particleSystemEntity=nullptr)
Retrieves entity by mouse position.
Definition: Engine.h:1275
static constexpr int ENGINETHREADSQUEUE_PRERENDER_DISPATCH_COUNT
Definition: Engine.h:190
Timing * getTiming()
Definition: Engine.h:1064
int registerModel(Model *model)
Register model.
Definition: Engine.h:1545
static bool is4K()
Definition: Engine.h:685
static STATIC_DLL_IMPEXT int32_t shadowMapWidth
Definition: Engine.h:231
void render(FrameBuffer *renderFrameBuffer, GeometryBuffer *renderGeometryBuffer, Camera *rendererCamera, DecomposedEntities &visibleDecomposedEntities, int32_t effectPass, int32_t renderPassMask, const string &shaderPrefix, bool applyShadowMapping, bool applyPostProcessing, bool doRenderLightSource, bool doRenderParticleSystems, int32_t renderTypes, bool skyShaderEnabled)
Do a render/effect pass.
Definition: Engine.cpp:2304
static int32_t getEnvironmentMappingHeight()
Definition: Engine.h:776
void loadTextures(const string &pathName)
Load textures.
Definition: Engine.cpp:289
int32_t scaledWidth
Definition: Engine.h:282
void removeEntityFromLists(Entity *entity)
Remove entity.
Definition: Engine.cpp:674
static MeshManager * getMeshManager()
Definition: Engine.h:441
Camera * getGizmoCamera()
Definition: Engine.h:1078
unordered_map< string, unordered_map< string, ShaderParameter > > shaderParameters
Definition: Engine.h:326
bool isUsingPostProcessingTemporaryFrameBuffer
Definition: Engine.h:324
static STATIC_DLL_IMPEXT unique_ptr< SkinningShader > skinningShader
Definition: Engine.h:219
DecomposedEntities visibleDecomposedEntities
Definition: Engine.h:311
void resetLists(DecomposedEntities &decomposedEntites)
Reset lists.
Definition: Engine.cpp:1057
static const vector< string > getShaderParameterNames(const string &shaderId)
Returns shader parameter names of shader with given id.
Definition: Engine.h:896
unique_ptr< FrameBuffer > gizmoFrameBuffer
Definition: Engine.h:295
void preRender(Camera *camera, DecomposedEntities &decomposedEntites, bool autoEmit, bool computeAnimations)
Computes visibility and animations and other pre render steps.
Definition: Engine.cpp:1233
static uint8_t getUniqueShaderId(const string &shaderId)
Definition: Engine.h:823
static SkinningShader * getSkinningShader()
Definition: Engine.h:469
int32_t scaledHeight
Definition: Engine.h:283
void registerEntity(Entity *entity)
Adds a entity to internal lists, those entities can also be sub entities from entity hierarchy or par...
Definition: Engine.cpp:437
static LinesShader * getLinesShader()
Definition: Engine.h:462
int32_t getScaledHeight()
Definition: Engine.h:1050
static constexpr int ENGINETHREADSQUEUE_RENDER_DISPATCH_COUNT
Definition: Engine.h:189
static STATIC_DLL_IMPEXT unordered_map< string, Shader * > shadersById
Definition: Engine.h:255
static const vector< Shader::ParameterDefaults > * getShaderParameterDefaults(const string &shaderId)
Returns parameter defaults of shader with given id.
Definition: Engine.h:882
static ShadowMapCreationShader * getShadowMapCreationShader()
Definition: Engine.h:656
array< unique_ptr< Light >, LIGHTS_MAX > lights
Definition: Engine.h:291
Entity hierarchy to be used with engine class.
Engine entity.
Definition: Entity.h:30
Environment mapping entity.
Fog particle system entity to be used with engine class.
Frame buffer class.
Definition: FrameBuffer.h:22
Geometry buffer class.
Imposter object to be used with engine class.
LOD object + imposter to be used with engine class.
LOD object to be used with engine class.
Definition: LODObject.h:49
Light representation.
Definition: Light.h:33
Lines entity to be used with engine class.
Definition: Lines.h:38
Object particle system entity to be used with engine class.
Object render group for static objects that might be animated by shaders.
Object to be used with engine class.
Definition: Object.h:60
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.
Timing class.
Definition: Timing.h:16
Represents a material.
Definition: Material.h:23
Representation of a 3D model.
Definition: Model.h:35
Model node.
Definition: Node.h:32
Interface to lighting shader program.
Engine connector of GL2 renderer to other engine functionality.
Engine connector of GL3 renderer to other engine functionality.
Engine connector of GLES2 renderer to other engine functionality.
Engine connector of VK renderer to other engine functionality.
virtual const Renderer_Statistics getStatistics()=0
Buffers used to transfer data between main memory to graphics board memory.
Definition: ObjectBuffer.h:24
Object node mesh specifically for rendering.
Object node specifically for rendering.
Definition: ObjectNode.h:41
Interface to compute shader skinning shader program.
GUI module class.
Definition: GUI.h:64
GUI node base class.
Definition: GUINode.h:64
GUI font class.
Definition: GUIFont.h:41
Matrix3x3 class representing matrix3x3 mathematical structure and operations for 2d space.
Definition: Matrix3x3.h:20
Matrix4x4 class representing matrix4x4 mathematical structure and operations for 3d space.
Definition: Matrix4x4.h:23
Vector2 class representing vector2 mathematical structure and operations with x, y components.
Definition: Vector2.h:20
Vector3 class representing vector3 mathematical structure and operations with x, y,...
Definition: Vector3.h:20
Consumer/producer queue.
Definition: Queue.h:26
Base class for threads.
Definition: Thread.h:20
Console class.
Definition: Console.h:29
Pool template class.
Definition: Pool.h:20
vector< EntityHierarchy * > entityHierarchies
Definition: Engine.h:272
vector< LODObject * > lodObjects
Definition: Engine.h:264
vector< EnvironmentMapping * > environmentMappingEntities
Definition: Engine.h:273
vector< ParticleSystemGroup * > psgs
Definition: Engine.h:268
vector< Object * > objectsPostPostProcessing
Definition: Engine.h:261
vector< ObjectParticleSystem * > opses
Definition: Engine.h:266
vector< ObjectRenderGroup * > objectRenderGroups
Definition: Engine.h:271
vector< Object * > requireComputeAnimationEntities
Definition: Engine.h:275
vector< LODObjectImposter * > lodObjectsImposter
Definition: Engine.h:265
vector< Entity * > noFrustumCullingEntities
Definition: Engine.h:258
vector< Object * > objectsNoDepthTest
Definition: Engine.h:262
vector< Object * > objectsForwardShading
Definition: Engine.h:260
vector< Object * > requirePreRenderEntities
Definition: Engine.h:274
struct tdme::engine::Engine::EngineThreadQueueElement::@0 animations
struct tdme::engine::Engine::EngineThreadQueueElement::@1 rendering
const vector< ParameterDefaults > parameterDefaults
Definition: Engine.h:250
const ShaderType type
Definition: Engine.h:248
unordered_map< string, const ParameterDefaults * > parameterDefaultsByName
Definition: Engine.h:251
Particle system entity interface.
Partition interface.
Definition: Partition.h:18
Action Interface.
Definition: Action.h:11
#define STATIC_DLL_IMPEXT
Definition: tdme.h:15
#define FORBID_CLASS_COPY(CLASS)
Definition: tdme.h:6