Ajout de l'ensemble du workspace.
[GPU.git] / WCudaMSE / BilatTools_Cuda_Image / src / core / cudaImageTools / bitmap / cpp / AnimateurFreeGL.cpp
diff --git a/WCudaMSE/BilatTools_Cuda_Image/src/core/cudaImageTools/bitmap/cpp/AnimateurFreeGL.cpp b/WCudaMSE/BilatTools_Cuda_Image/src/core/cudaImageTools/bitmap/cpp/AnimateurFreeGL.cpp
new file mode 100755 (executable)
index 0000000..6d2a14c
--- /dev/null
@@ -0,0 +1,114 @@
+#include <iostream>\r
+\r
+#include "cudaTools.h"\r
+#include "Device.h"\r
+#include "MathTools.h"\r
+\r
+#include "Chronos.h"\r
+\r
+#include "AnimateurFreeGL.h"\r
+\r
+using std::cout;\r
+using std::endl;\r
+\r
+/*----------------------------------------------------------------------*\\r
+ |*                    Declaration                                     *|\r
+ \*---------------------------------------------------------------------*/\r
+\r
+/*--------------------------------------*\\r
+ |*            Imported                *|\r
+ \*-------------------------------------*/\r
+\r
+/*--------------------------------------*\\r
+ |*            Public                  *|\r
+ \*-------------------------------------*/\r
+\r
+/*--------------------------------------*\\r
+ |*            Private                 *|\r
+ \*-------------------------------------*/\r
+\r
+/*----------------------------------------------------------------------*\\r
+ |*                    Implementation                                  *|\r
+ \*---------------------------------------------------------------------*/\r
+\r
+/*--------------------------------------*\\r
+ |*            Public                  *|\r
+ \*-------------------------------------*/\r
+\r
+AnimateurFreeGL::AnimateurFreeGL(Animable_I* ptrAnimable, int nbIteration)\r
+    {\r
+    // Input\r
+    this->nbIteration = nbIteration;\r
+    this->ptrAnimable = ptrAnimable;\r
+\r
+    // Outputs\r
+    this->fps = -1;\r
+    this->timeElapseS = -1;\r
+\r
+    start();\r
+    printStat();\r
+    }\r
+\r
+AnimateurFreeGL::~AnimateurFreeGL()\r
+    {\r
+    delete ptrAnimable; // discutable!\r
+    }\r
+\r
+int AnimateurFreeGL::getFps(void)\r
+    {\r
+    return fps;\r
+    }\r
+\r
+/*--------------------------------------*\\r
+ |*            Private                 *|\r
+ \*-------------------------------------*/\r
+\r
+int AnimateurFreeGL::start()\r
+    {\r
+    cout << "\n[AnimateurFreeGL] : started : " << ptrAnimable->getTitle() << endl;\r
+\r
+    int w = ptrAnimable->getW();\r
+    int h = ptrAnimable->getH();\r
+    size_t size = w * h * sizeof(uchar4);\r
+\r
+    uchar4* ptrDevImage;\r
+    HANDLE_ERROR(cudaMalloc((void**) &ptrDevImage, size));\r
+    HANDLE_ERROR(cudaMemset(ptrDevImage, 0, size));\r
+\r
+    int i = 0;\r
+    Chronos chrono;\r
+    const char* messageError=ptrAnimable->getTitle().c_str();\r
+    while (i < nbIteration)\r
+       {\r
+       ptrAnimable->runGPU(ptrDevImage);\r
+\r
+       Device::checkKernelError(messageError);\r
+       Device::synchronize(); // Important!\r
+\r
+       ptrAnimable->animationStep();\r
+\r
+       i++;\r
+       }\r
+\r
+    chrono.stop();\r
+    HANDLE_ERROR(cudaFree(ptrDevImage));\r
+\r
+    this->timeElapseS = chrono.getDeltaTime();\r
+    this->fps = nbIteration / timeElapseS;\r
+\r
+    return fps;\r
+    }\r
+\r
+void AnimateurFreeGL::printStat()\r
+    {\r
+    cout << endl;\r
+    cout << "Benchmark   : [" << ptrAnimable->getTitle()<<"]"  << endl;\r
+    cout << "#Iteration  : " << nbIteration << endl;\r
+    cout << "#secondes   : " << timeElapseS << " (s)" << endl;\r
+    cout << "#fps        : " << fps << endl;\r
+    }\r
+\r
+/*----------------------------------------------------------------------*\\r
+ |*                    End                                             *|\r
+ \*---------------------------------------------------------------------*/\r
+\r