nux-1.14.0
|
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 t_u32 RenderingStats::m_NumTex2D = 0; 00038 t_u32 RenderingStats::m_GPUSizeTex2D = 0; 00039 t_u32 RenderingStats::m_NumTexRectangle = 0; 00040 t_u32 RenderingStats::m_GPUSizeTexRectangle = 0; 00041 t_u32 RenderingStats::m_NumTexCube = 0; 00042 t_u32 RenderingStats::m_GPUSizeTexCube = 0; 00043 t_u32 RenderingStats::m_NumTexVolume = 0; 00044 t_u32 RenderingStats::m_GPUSizeTexVolume = 0; 00045 00046 t_u32 RenderingStats::m_NumTexAnimated = 0; 00047 t_u32 RenderingStats::m_GPUSizeTexAnimated = 0; 00048 00049 t_u32 RenderingStats::m_NumPBO = 0; // Counted as Vertex Buffer 00050 t_u32 RenderingStats::m_GPUSizePBO = 0; // Counted as Vertex Buffer 00051 t_u32 RenderingStats::m_NumQueryObject = 0; 00052 t_u32 RenderingStats::m_NumFrameBufferObject = 0; 00053 t_u32 RenderingStats::m_NumVertexBuffer = 0; 00054 t_u32 RenderingStats::m_GPUSizeVertexBuffer = 0; 00055 t_u32 RenderingStats::m_NumIndexBuffer = 0; 00056 t_u32 RenderingStats::m_GPUSizeIndexBuffer = 0; 00057 t_u32 RenderingStats::m_NumVertexShader = 0; 00058 t_u32 RenderingStats::m_NumPixelShader = 0; 00059 t_u32 RenderingStats::m_NumShaderProgram = 0; 00060 00061 t_u32 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 _texture_2d_array.push_back (NUX_STATIC_CAST (IOpenGLBaseTexture *, GraphicsObject)->GetOpenGLID() ); 00118 m_NumTex2D++; 00119 m_GPUSizeTex2D += GetTextureSize (NUX_REINTERPRET_CAST (IOpenGLBaseTexture *, GraphicsObject) ); 00120 m_TotalGPUSize += m_GPUSizeTex2D; 00121 break; 00122 } 00123 case RTTEXTURERECTANGLE: 00124 { 00125 _texture_rect_array.push_back (NUX_STATIC_CAST (IOpenGLBaseTexture *, GraphicsObject)->GetOpenGLID() ); 00126 m_NumTexRectangle++; 00127 m_GPUSizeTexRectangle += GetTextureSize (NUX_REINTERPRET_CAST (IOpenGLBaseTexture *, GraphicsObject) ); 00128 m_TotalGPUSize += m_GPUSizeTexRectangle; 00129 break; 00130 } 00131 case RTCUBETEXTURE: 00132 { 00133 m_NumTexCube++; 00134 m_GPUSizeTexCube += GetTextureSize (NUX_STATIC_CAST (IOpenGLBaseTexture *, GraphicsObject) ); 00135 m_TotalGPUSize += m_GPUSizeTexCube; 00136 break; 00137 } 00138 case RTVOLUMETEXTURE: 00139 { 00140 m_NumTexVolume++; 00141 m_GPUSizeTexVolume += GetTextureSize (NUX_STATIC_CAST (IOpenGLBaseTexture *, GraphicsObject) ); 00142 m_TotalGPUSize += m_GPUSizeTexVolume; 00143 break; 00144 } 00145 case RTANIMATEDTEXTURE: 00146 { 00147 // Animated texture size is compted as rectangle textures; 00148 m_NumTexAnimated++; 00149 break; 00150 } 00151 case RTQUERY: 00152 { 00153 m_NumQueryObject++; 00154 break; 00155 } 00156 case RTFRAMEBUFFEROBJECT: 00157 { 00158 m_NumFrameBufferObject++; 00159 break; 00160 } 00161 default: 00162 break; 00163 } 00164 00165 } 00166 void RenderingStats::UnRegister (IOpenGLResource *GraphicsObject) 00167 { 00168 switch (GraphicsObject->GetResourceType() ) 00169 { 00170 case RTINDEXBUFFER: 00171 { 00172 m_NumIndexBuffer--; 00173 m_GPUSizeIndexBuffer -= NUX_REINTERPRET_CAST (IOpenGLIndexBuffer *, GraphicsObject)->GetSize(); 00174 m_TotalGPUSize -= m_GPUSizeIndexBuffer; 00175 break; 00176 } 00177 case RTVERTEXBUFFER: 00178 { 00179 m_NumVertexBuffer--; 00180 m_GPUSizeVertexBuffer -= NUX_REINTERPRET_CAST (IOpenGLVertexBuffer *, GraphicsObject)->GetSize(); 00181 m_TotalGPUSize -= m_GPUSizeVertexBuffer; 00182 break; 00183 } 00184 case RTTEXTURE: 00185 { 00186 std::vector<int>::iterator it; 00187 it = std::find (_texture_2d_array.begin(), _texture_2d_array.end(), NUX_STATIC_CAST (IOpenGLBaseTexture *, GraphicsObject)->GetOpenGLID() ); 00188 00189 if (it != _texture_2d_array.end() ) 00190 _texture_2d_array.erase (it); 00191 00192 m_NumTex2D--; 00193 m_GPUSizeTex2D -= GetTextureSize (NUX_REINTERPRET_CAST (IOpenGLBaseTexture *, GraphicsObject) ); 00194 m_TotalGPUSize -= m_GPUSizeTex2D; 00195 break; 00196 } 00197 case RTTEXTURERECTANGLE: 00198 { 00199 std::vector<int>::iterator it; 00200 it = std::find (_texture_rect_array.begin(), _texture_rect_array.end(), NUX_STATIC_CAST (IOpenGLBaseTexture *, GraphicsObject)->GetOpenGLID() ); 00201 00202 if (it != _texture_rect_array.end() ) 00203 _texture_rect_array.erase (it); 00204 00205 m_NumTexRectangle--; 00206 m_GPUSizeTexRectangle -= GetTextureSize (NUX_REINTERPRET_CAST (IOpenGLBaseTexture *, GraphicsObject) ); 00207 m_TotalGPUSize -= m_GPUSizeTexRectangle; 00208 break; 00209 } 00210 case RTCUBETEXTURE: 00211 { 00212 m_NumTexCube--; 00213 m_GPUSizeTexCube -= GetTextureSize (NUX_STATIC_CAST (IOpenGLBaseTexture *, GraphicsObject) ); 00214 m_TotalGPUSize -= m_GPUSizeTexCube; 00215 break; 00216 } 00217 case RTVOLUMETEXTURE: 00218 { 00219 m_NumTexVolume--; 00220 m_GPUSizeTexVolume -= GetTextureSize (NUX_STATIC_CAST (IOpenGLBaseTexture *, GraphicsObject) ); 00221 m_TotalGPUSize -= m_GPUSizeTexVolume; 00222 break; 00223 } 00224 case RTANIMATEDTEXTURE: 00225 { 00226 // Animated texture size is compted as rectangle textures; 00227 m_NumTexAnimated--; 00228 break; 00229 } 00230 case RTQUERY: 00231 { 00232 m_NumQueryObject--; 00233 break; 00234 } 00235 case RTFRAMEBUFFEROBJECT: 00236 { 00237 m_NumFrameBufferObject--; 00238 break; 00239 } 00240 default: 00241 break; 00242 } 00243 00244 } 00245 00246 }