2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 #include "gl-proxy-implementation.h"
24 #include <base/environment-options.h>
25 #include <dali/integration-api/debug.h>
29 const int NUM_FRAMES_PER_SECOND(60);
40 Sampler::Sampler( const char* description )
41 : mDescription( description ),
43 mAccumulatedSquare(0.0f),
51 void Sampler::Increment()
59 mAccumulatedSquare= 0.0f;
63 mCurrentFrameCount = 0;
66 void Sampler::Accumulate()
68 if( mNumSamples == 0 )
70 mMin = mCurrentFrameCount;
71 mMax = mCurrentFrameCount;
75 if(mCurrentFrameCount < mMin)
77 mMin = mCurrentFrameCount;
79 if(mCurrentFrameCount > mMax)
81 mMax = mCurrentFrameCount;
87 mAccumulated += mCurrentFrameCount;
88 mAccumulatedSquare += (mCurrentFrameCount * mCurrentFrameCount);
89 mCurrentFrameCount = 0;
91 const char* Sampler::GetDescription() const
96 float Sampler::GetMeanValue() const
101 meanValue = mAccumulated / (float)mNumSamples;
106 float Sampler::GetStandardDeviation() const
108 float standardDeviation=0.0f;
109 if( mNumSamples > 0 )
111 standardDeviation = sqrtf( mNumSamples * mAccumulatedSquare - (mAccumulated*mAccumulated)) / mNumSamples;
113 return standardDeviation;
116 float Sampler::GetMin() const
121 float Sampler::GetMax() const
126 GlProxyImplementation::GlProxyImplementation(EnvironmentOptions& environmentOptions)
127 : mEnvironmentOptions(environmentOptions),
128 mActiveTextureSampler( "ActiveTexture calls"),
129 mClearSampler("Clear calls"),
130 mBindBufferSampler( "Bind buffers"),
131 mBindTextureSampler( "Bind textures"),
132 mDrawSampler("Draw calls"),
133 mUniformSampler("Uniform sets"),
134 mUseProgramSampler("Used programs"),
141 GlProxyImplementation::~GlProxyImplementation()
145 void GlProxyImplementation::PreRender()
149 void GlProxyImplementation::PostRender( unsigned int timeDelta )
151 // Accumulate counts in each sampler
154 // When we reach the desired frame count, output the averages from the samples
156 if( mFrameCount >= mEnvironmentOptions.GetGlesCallTime() * NUM_FRAMES_PER_SECOND )
163 void GlProxyImplementation::ActiveTexture( GLenum texture )
165 mActiveTextureSampler.Increment();
166 GlImplementation::ActiveTexture(texture);
169 void GlProxyImplementation::Clear( GLbitfield mask )
171 mClearSampler.Increment();
172 GlImplementation::Clear(mask);
175 void GlProxyImplementation::BindBuffer( GLenum target, GLuint buffer )
177 mBindBufferSampler.Increment();
178 GlImplementation::BindBuffer(target,buffer);
181 void GlProxyImplementation::BindTexture( GLenum target, GLuint texture )
183 mBindTextureSampler.Increment();
184 GlImplementation::BindTexture(target,texture);
187 void GlProxyImplementation::DrawArrays( GLenum mode, GLint first, GLsizei count )
189 mDrawSampler.Increment();
190 GlImplementation::DrawArrays(mode,first,count);
193 void GlProxyImplementation::DrawElements( GLenum mode, GLsizei count, GLenum type, const void* indices )
195 mDrawSampler.Increment();
196 GlImplementation::DrawElements(mode,count,type,indices);
199 void GlProxyImplementation::Uniform1f( GLint location, GLfloat x )
201 mUniformSampler.Increment();
202 GlImplementation::Uniform1f(location,x);
205 void GlProxyImplementation::Uniform1fv( GLint location, GLsizei count, const GLfloat* v )
207 mUniformSampler.Increment();
208 GlImplementation::Uniform1fv(location,count,v);
211 void GlProxyImplementation::Uniform1i( GLint location, GLint x )
213 mUniformSampler.Increment();
214 GlImplementation::Uniform1i(location,x);
217 void GlProxyImplementation::Uniform1iv( GLint location, GLsizei count, const GLint* v )
219 mUniformSampler.Increment();
220 GlImplementation::Uniform1iv(location,count,v);
223 void GlProxyImplementation::Uniform2f( GLint location, GLfloat x, GLfloat y)
225 mUniformSampler.Increment();
226 GlImplementation::Uniform2f(location,x,y);
229 void GlProxyImplementation::Uniform2fv( GLint location, GLsizei count, const GLfloat* v )
231 mUniformSampler.Increment();
232 GlImplementation::Uniform2fv(location,count,v);
235 void GlProxyImplementation::Uniform2i( GLint location, GLint x, GLint y )
237 mUniformSampler.Increment();
238 GlImplementation::Uniform2i(location,x,y);
241 void GlProxyImplementation::Uniform2iv( GLint location, GLsizei count, const GLint* v )
243 mUniformSampler.Increment();
244 GlImplementation::Uniform2iv(location,count,v);
247 void GlProxyImplementation::Uniform3f( GLint location, GLfloat x, GLfloat y, GLfloat z)
249 mUniformSampler.Increment();
250 GlImplementation::Uniform3f(location,x,y,z);
253 void GlProxyImplementation::Uniform3fv( GLint location, GLsizei count, const GLfloat* v )
255 mUniformSampler.Increment();
256 GlImplementation::Uniform3fv(location,count,v);
259 void GlProxyImplementation::Uniform3i( GLint location, GLint x, GLint y, GLint z )
261 mUniformSampler.Increment();
262 GlImplementation::Uniform3i(location,x,y,z);
265 void GlProxyImplementation::Uniform3iv( GLint location, GLsizei count, const GLint* v )
267 mUniformSampler.Increment();
268 GlImplementation::Uniform3iv(location,count,v);
271 void GlProxyImplementation::Uniform4f( GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w )
273 mUniformSampler.Increment();
274 GlImplementation::Uniform4f(location,x,y,z,w);
277 void GlProxyImplementation::Uniform4fv( GLint location, GLsizei count, const GLfloat* v )
279 mUniformSampler.Increment();
280 GlImplementation::Uniform4fv(location,count,v);
283 void GlProxyImplementation::Uniform4i( GLint location, GLint x, GLint y, GLint z, GLint w )
285 mUniformSampler.Increment();
286 GlImplementation::Uniform4i(location,x,y,z,w);
289 void GlProxyImplementation::Uniform4iv( GLint location, GLsizei count, const GLint* v )
291 mUniformSampler.Increment();
292 GlImplementation::Uniform4iv(location,count,v);
295 void GlProxyImplementation::UniformMatrix2fv( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value )
297 mUniformSampler.Increment();
298 GlImplementation::UniformMatrix2fv(location,count,transpose,value);
301 void GlProxyImplementation::UniformMatrix3fv( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value )
303 mUniformSampler.Increment();
304 GlImplementation::UniformMatrix3fv(location,count,transpose,value);
307 void GlProxyImplementation::UniformMatrix4fv( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value )
309 mUniformSampler.Increment();
310 GlImplementation::UniformMatrix4fv(location,count,transpose,value);
313 void GlProxyImplementation::UseProgram( GLuint program )
315 mUseProgramSampler.Increment();
316 GlImplementation::UseProgram(program);
319 void GlProxyImplementation::AccumulateSamples()
321 // Accumulate counts in each sampler
322 mActiveTextureSampler.Accumulate();
323 mClearSampler.Accumulate();
324 mBindBufferSampler.Accumulate();
325 mBindTextureSampler.Accumulate();
326 mDrawSampler.Accumulate();
327 mUniformSampler.Accumulate();
328 mUseProgramSampler.Accumulate();
331 void GlProxyImplementation::LogResults()
333 Debug::LogMessage( Debug::DebugInfo, "OpenGL ES statistics sampled over %d frames) operations per frame:\n", mFrameCount );
334 LogCalls( mActiveTextureSampler );
335 LogCalls( mClearSampler );
336 LogCalls( mBindBufferSampler );
337 LogCalls( mBindTextureSampler );
338 LogCalls( mDrawSampler );
339 LogCalls( mUniformSampler );
340 LogCalls( mUseProgramSampler );
343 void GlProxyImplementation::LogCalls( const Sampler& sampler )
345 Debug::LogMessage( Debug::DebugInfo, " %s : Mean %5.2f (Min:%5.2f, Max:%5.2f, StdDev:%5.2f)\n",
346 sampler.GetDescription(),
347 sampler.GetMeanValue(), sampler.GetMin(), sampler.GetMax(),
348 sampler.GetStandardDeviation() );
351 void GlProxyImplementation::ResetSamplers()
353 mActiveTextureSampler.Reset();
354 mClearSampler.Reset();
355 mBindBufferSampler.Reset();
356 mBindTextureSampler.Reset();
357 mDrawSampler.Reset();
358 mUniformSampler.Reset();
359 mUseProgramSampler.Reset();
363 } // namespace Adaptor
365 } // namespace Internal