renderstat.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * DoRayMe - a quick and dirty Raytracer
  3. * Render statistics header
  4. *
  5. * Created by Manoël Trapier
  6. * Copyright (c) 2020 986-Studio.
  7. *
  8. */
  9. #ifndef DORAYME_RENDERSTAT_H
  10. #define DORAYME_RENDERSTAT_H
  11. #include <stdint.h>
  12. #ifdef RENDER_STATS
  13. #include <stdio.h>
  14. class RenderStats
  15. {
  16. private:
  17. uint64_t coneCount; /* Total number of cones */
  18. uint64_t cylinderCount; /* Total number of cylinder */
  19. uint64_t cubeCount; /* Total number of cubes */
  20. uint64_t groupCount; /* Total number of groups */
  21. uint64_t lightCount; /* Total number of light */
  22. uint64_t planeCount; /* Total number of plane */
  23. uint64_t sphereCount; /* Total number of sphere */
  24. uint64_t triangleCount; /* Total number of triangle */
  25. uint64_t pixelCount; /* Total number of rendered pixels */
  26. uint64_t rayCount; /* Total number of rays */
  27. uint64_t lightRayEmitedCount; /* Total number of ray launched for light tests */
  28. uint64_t reflectionRayCount; /* Total number of reflection ray launched */
  29. uint64_t refractedRayCount; /* Total number of refracted ray launched */
  30. uint64_t intersectCount; /* Total number of intersect object created */
  31. uint64_t intersectionCount; /* Total number of intersection for all casted rays, including light and reflections */
  32. uint64_t reallocCallCount; /* Total number of time realloc being called */
  33. uint64_t mallocCallCount; /* Total number of time malloc/calloc being called */
  34. uint64_t discardedIntersectCount; /* Number of time a bounding box check said "no need to test me" */
  35. uint64_t maxDepthAttained; /* Report the lowest depth attained during ray recursion */
  36. uint64_t maxIntersectOnARay; /* Biggest intersect done */
  37. public:
  38. RenderStats() : coneCount(0), cylinderCount(0), cubeCount(0), groupCount(0), lightCount(0), planeCount(0), sphereCount(0), triangleCount(0),
  39. pixelCount(0), rayCount(0), lightRayEmitedCount(0), reflectionRayCount(0), refractedRayCount(0),
  40. intersectCount(0), intersectionCount(0), reallocCallCount(0), mallocCallCount(0),
  41. discardedIntersectCount(0), maxDepthAttained(UINT64_MAX), maxIntersectOnARay(0) {};
  42. void addCone() { this->coneCount++; };
  43. void addCylinder() { this->cylinderCount++; };
  44. void addCube() { this->cubeCount++; };
  45. void addGroup() { this->groupCount++; };
  46. void addLight() { this->lightCount++; };
  47. void addPlane() { this->planeCount++; };
  48. void addSphere() { this->sphereCount++; };
  49. void addTriangle() { this->triangleCount++; };
  50. void addPixel() { this->pixelCount++; };
  51. void addRay() { this->rayCount++; };
  52. void addLightRay() { this->lightRayEmitedCount++; };
  53. void addReflectRay() { this->reflectionRayCount++; };
  54. void addRefractRay() { this->refractedRayCount++; };
  55. void addIntersect() { this->intersectCount++; };
  56. void addIntersection() { this->intersectionCount++; };
  57. void addMalloc() { this->mallocCallCount++; };
  58. void addRealloc() { this->reallocCallCount++; };
  59. void addDiscardedIntersect() { this->discardedIntersectCount++; };
  60. void setMaxDepth(uint32_t depth) { if (this->maxDepthAttained>depth) { this->maxDepthAttained = depth; } };
  61. void setMaxIntersect(uint32_t count) { if (this->maxIntersectOnARay<count) { this->maxIntersectOnARay = count; } };
  62. void printStats() {
  63. printf("Rendering statistics:\n");
  64. printf("Cones : %lld\n", this->coneCount);
  65. printf("Cubes : %lld\n", this->cubeCount);
  66. printf("Cylinders : %lld\n", this->cylinderCount);
  67. printf("Groups : %lld\n", this->groupCount);
  68. printf("Lights : %lld\n", this->lightCount);
  69. printf("Planes : %lld\n", this->planeCount);
  70. printf("Spheres : %lld\n", this->sphereCount);
  71. printf("Triangles : %lld\n", this->triangleCount);
  72. printf("==================================================\n");
  73. printf("Pixel rendered : %lld\n", this->pixelCount);
  74. printf("Ray casted : %lld\n", this->rayCount);
  75. printf("Light Ray casted : %lld\n", this->lightRayEmitedCount);
  76. printf("Reflection ray casted : %lld\n", this->reflectionRayCount);
  77. printf("Refraction ray casted : %lld\n", this->refractedRayCount);
  78. printf("Intersect object created: %lld\n", this->intersectCount);
  79. printf("Intersection created : %lld\n", this->intersectionCount);
  80. printf("Malloc called : %lld\n", this->mallocCallCount);
  81. printf("Realloc called : %lld\n", this->reallocCallCount);
  82. printf("Bounding box missed : %lld\n", this->discardedIntersectCount);
  83. printf("Min depth atteined : %lld\n", this->maxDepthAttained);
  84. printf("Max intersect count : %lld\n", this->maxIntersectOnARay);
  85. printf("==================================================\n");
  86. };
  87. };
  88. #else
  89. class RenderStats
  90. {
  91. public:
  92. static void addCone() {};
  93. static void addCylinder() {};
  94. static void addCube() {};
  95. static void addGroup() {};
  96. static void addLight() {};
  97. static void addPlane() {};
  98. static void addSphere() {};
  99. static void addTriangle() {};
  100. static void printStats() {};
  101. static void addPixel() {};
  102. static void addRay() {};
  103. static void addLightRay() {};
  104. static void addReflectRay() {};
  105. static void addRefractRay() {};
  106. static void addIntersection() {};
  107. static void addDiscardedIntersect() {};
  108. static void setMaxDepth(uint32_t depth) {};
  109. static void addIntersect() {};
  110. static void addMalloc() {};
  111. static void addRealloc() {};
  112. static void setMaxIntersect(uint32_t count) {};
  113. };
  114. #endif
  115. extern RenderStats stats;
  116. #endif /* DORAYME_RENDERSTAT_H */