Back to index

nux  3.0.0
RunTimeStats.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2010 Inalogic® Inc.
00003  *
00004  * This program is free software: you can redistribute it and/or modify it
00005  * under the terms of the GNU Lesser General Public License, as
00006  * published by the  Free Software Foundation; either version 2.1 or 3.0
00007  * of the License.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranties of
00011  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00012  * PURPOSE.  See the applicable version of the GNU Lesser General Public
00013  * License for more details.
00014  *
00015  * You should have received a copy of both the GNU Lesser General Public
00016  * License along with this program. If not, see <http://www.gnu.org/licenses/>
00017  *
00018  * Authored by: Jay Taoko <jaytaoko@inalogic.com>
00019  *
00020  */
00021 
00022 #include <iostream>
00023 
00024 #include "GLResource.h"
00025 #include "IOpenGLResource.h"
00026 #include "IOpenGLBaseTexture.h"
00027 #include "IOpenGLIndexBuffer.h"
00028 #include "IOpenGLVertexBuffer.h"
00029 #include "RunTimeStats.h"
00030 
00031 
00032 namespace nux
00033 {
00034 
00035   NUX_IMPLEMENT_GLOBAL_OBJECT(RenderingStats);
00036 
00037   unsigned int RenderingStats::m_NumTex2D = 0;
00038   unsigned int RenderingStats::m_GPUSizeTex2D = 0;
00039   unsigned int RenderingStats::m_NumTexRectangle = 0;
00040   unsigned int RenderingStats::m_GPUSizeTexRectangle = 0;
00041   unsigned int RenderingStats::m_NumTexCube = 0;
00042   unsigned int RenderingStats::m_GPUSizeTexCube = 0;
00043   unsigned int RenderingStats::m_NumTexVolume = 0;
00044   unsigned int RenderingStats::m_GPUSizeTexVolume = 0;
00045 
00046   unsigned int RenderingStats::m_NumTexAnimated = 0;
00047   unsigned int RenderingStats::m_GPUSizeTexAnimated = 0;
00048 
00049   unsigned int RenderingStats::m_NumPBO = 0; // Counted as Vertex Buffer
00050   unsigned int RenderingStats::m_GPUSizePBO = 0; // Counted as Vertex Buffer
00051   unsigned int RenderingStats::m_NumQueryObject = 0;
00052   unsigned int RenderingStats::m_NumFrameBufferObject = 0;
00053   unsigned int RenderingStats::m_NumVertexBuffer = 0;
00054   unsigned int RenderingStats::m_GPUSizeVertexBuffer = 0;
00055   unsigned int RenderingStats::m_NumIndexBuffer = 0;
00056   unsigned int RenderingStats::m_GPUSizeIndexBuffer = 0;
00057   unsigned int RenderingStats::m_NumVertexShader = 0;
00058   unsigned int RenderingStats::m_NumPixelShader = 0;
00059   unsigned int RenderingStats::m_NumShaderProgram = 0;
00060 
00061   unsigned int RenderingStats::m_TotalGPUSize = 0;
00062 
00063   void RenderingStats::Constructor()
00064   {
00065 
00066   }
00067 
00068   void RenderingStats::Destructor()
00069   {
00070 #ifdef DEBUG
00071     if (m_NumIndexBuffer != 0)
00072     {
00073       std::cerr << "[RenderingStats::Destructor] Some index buffers have not been released.";
00074     }
00075 
00076     if (m_NumTex2D != 0)
00077     {
00078       std::cerr << "[RenderingStats::Destructor] Some 2D textures have not been released.";
00079       for (auto id: _texture_2d_array)
00080       {
00081         std::cerr << "[RenderingStats::Destructor] Remaining 2D textures: " << id;
00082       }
00083     }
00084 
00085     if (m_NumTexRectangle != 0)
00086     {
00087       std::cerr << "[RenderingStats::Destructor] Some rectangle textures buffers have not been released.";
00088 
00089       for (auto id: _texture_rect_array)
00090       {
00091         std::cerr << "[RenderingStats::Destructor] Remaining Rectangle textures: " << id;
00092       }
00093     }
00094 #endif
00095   }
00096 
00097   void RenderingStats::Register(IOpenGLResource *GraphicsObject)
00098   {
00099     switch(GraphicsObject->GetResourceType())
00100     {
00101       case RTINDEXBUFFER:
00102       {
00103         m_NumIndexBuffer++;
00104         m_GPUSizeIndexBuffer += NUX_REINTERPRET_CAST(IOpenGLIndexBuffer *, GraphicsObject)->GetSize();
00105         m_TotalGPUSize += m_GPUSizeIndexBuffer;
00106         break;
00107       }
00108       case RTVERTEXBUFFER:
00109       {
00110         m_NumVertexBuffer++;
00111         m_GPUSizeVertexBuffer += NUX_REINTERPRET_CAST(IOpenGLVertexBuffer *, GraphicsObject)->GetSize();
00112         m_TotalGPUSize += m_GPUSizeVertexBuffer;
00113         break;
00114       }
00115       case RTTEXTURE:
00116       {
00117         int id = NUX_STATIC_CAST(IOpenGLBaseTexture *, GraphicsObject)->GetOpenGLID();
00118         if (id)
00119           _texture_2d_array.push_back(NUX_STATIC_CAST(IOpenGLBaseTexture *, GraphicsObject)->GetOpenGLID());
00120         m_NumTex2D++;
00121         m_GPUSizeTex2D += GetTextureSize(NUX_REINTERPRET_CAST(IOpenGLBaseTexture *, GraphicsObject));
00122         m_TotalGPUSize += m_GPUSizeTex2D;
00123         break;
00124       }
00125       case RTTEXTURERECTANGLE:
00126       {
00127         int id = NUX_STATIC_CAST(IOpenGLBaseTexture *, GraphicsObject)->GetOpenGLID();
00128         if (id)
00129           _texture_rect_array.push_back(NUX_STATIC_CAST(IOpenGLBaseTexture *, GraphicsObject)->GetOpenGLID());
00130         m_NumTexRectangle++;
00131         m_GPUSizeTexRectangle += GetTextureSize(NUX_REINTERPRET_CAST(IOpenGLBaseTexture *, GraphicsObject));
00132         m_TotalGPUSize += m_GPUSizeTexRectangle;
00133         break;
00134       }
00135       case RTCUBETEXTURE:
00136       {
00137         m_NumTexCube++;
00138         m_GPUSizeTexCube += GetTextureSize(NUX_STATIC_CAST(IOpenGLBaseTexture *, GraphicsObject));
00139         m_TotalGPUSize += m_GPUSizeTexCube;
00140         break;
00141       }
00142       case RTVOLUMETEXTURE:
00143       {
00144         m_NumTexVolume++;
00145         m_GPUSizeTexVolume += GetTextureSize(NUX_STATIC_CAST(IOpenGLBaseTexture *, GraphicsObject));
00146         m_TotalGPUSize += m_GPUSizeTexVolume;
00147         break;
00148       }
00149       case RTANIMATEDTEXTURE:
00150       {
00151         // Animated texture size is compted as rectangle textures;
00152         m_NumTexAnimated++;
00153         break;
00154       }
00155       case RTQUERY:
00156       {
00157         m_NumQueryObject++;
00158         break;
00159       }
00160       case RTFRAMEBUFFEROBJECT:
00161       {
00162         m_NumFrameBufferObject++;
00163         break;
00164       }
00165       default:
00166         break;
00167     }
00168 
00169   }
00170   void RenderingStats::UnRegister(IOpenGLResource *GraphicsObject)
00171   {
00172     switch(GraphicsObject->GetResourceType())
00173     {
00174       case RTINDEXBUFFER:
00175       {
00176         m_NumIndexBuffer--;
00177         m_GPUSizeIndexBuffer -= NUX_REINTERPRET_CAST(IOpenGLIndexBuffer *, GraphicsObject)->GetSize();
00178         m_TotalGPUSize -= m_GPUSizeIndexBuffer;
00179         break;
00180       }
00181       case RTVERTEXBUFFER:
00182       {
00183         m_NumVertexBuffer--;
00184         m_GPUSizeVertexBuffer -= NUX_REINTERPRET_CAST(IOpenGLVertexBuffer *, GraphicsObject)->GetSize();
00185         m_TotalGPUSize -= m_GPUSizeVertexBuffer;
00186         break;
00187       }
00188       case RTTEXTURE:
00189       {
00190         int id = NUX_STATIC_CAST(IOpenGLBaseTexture *, GraphicsObject)->GetOpenGLID();
00191         _texture_2d_array.erase(std::remove(_texture_2d_array.begin(), _texture_2d_array.end(), id), _texture_2d_array.end());
00192 
00193         m_NumTex2D--;
00194         m_GPUSizeTex2D -= GetTextureSize(NUX_REINTERPRET_CAST(IOpenGLBaseTexture *, GraphicsObject));
00195         m_TotalGPUSize -= m_GPUSizeTex2D;
00196         break;
00197       }
00198       case RTTEXTURERECTANGLE:
00199       {
00200         int id = NUX_STATIC_CAST(IOpenGLBaseTexture *, GraphicsObject)->GetOpenGLID();
00201         _texture_rect_array.erase(std::remove(_texture_rect_array.begin(), _texture_rect_array.end(), id), _texture_rect_array.end());
00202 
00203         m_NumTexRectangle--;
00204         m_GPUSizeTexRectangle -= GetTextureSize(NUX_REINTERPRET_CAST(IOpenGLBaseTexture *, GraphicsObject));
00205         m_TotalGPUSize -= m_GPUSizeTexRectangle;
00206         break;
00207       }
00208       case RTCUBETEXTURE:
00209       {
00210         m_NumTexCube--;
00211         m_GPUSizeTexCube -= GetTextureSize(NUX_STATIC_CAST(IOpenGLBaseTexture *, GraphicsObject));
00212         m_TotalGPUSize -= m_GPUSizeTexCube;
00213         break;
00214       }
00215       case RTVOLUMETEXTURE:
00216       {
00217         m_NumTexVolume--;
00218         m_GPUSizeTexVolume -= GetTextureSize(NUX_STATIC_CAST(IOpenGLBaseTexture *, GraphicsObject));
00219         m_TotalGPUSize -= m_GPUSizeTexVolume;
00220         break;
00221       }
00222       case RTANIMATEDTEXTURE:
00223       {
00224         // Animated texture size is compted as rectangle textures;
00225         m_NumTexAnimated--;
00226         break;
00227       }
00228       case RTQUERY:
00229       {
00230         m_NumQueryObject--;
00231         break;
00232       }
00233       case RTFRAMEBUFFEROBJECT:
00234       {
00235         m_NumFrameBufferObject--;
00236         break;
00237       }
00238       default:
00239         break;
00240     }
00241 
00242   }
00243 
00244 }