2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "gl-proxy-implementation.h"
25 #include <base/environment-options.h>
26 #include <dali/integration-api/debug.h>
30 const int NUM_FRAMES_PER_SECOND(60);
41 Sampler::Sampler( const char* description )
42 : mDescription( description ),
44 mAccumulatedSquare(0.0f),
52 void Sampler::Increment()
60 mAccumulatedSquare= 0.0f;
64 mCurrentFrameCount = 0;
67 void Sampler::Accumulate()
69 if( mNumSamples == 0 )
71 mMin = mCurrentFrameCount;
72 mMax = mCurrentFrameCount;
76 if(mCurrentFrameCount < mMin)
78 mMin = mCurrentFrameCount;
80 if(mCurrentFrameCount > mMax)
82 mMax = mCurrentFrameCount;
88 mAccumulated += mCurrentFrameCount;
89 mAccumulatedSquare += (mCurrentFrameCount * mCurrentFrameCount);
90 mCurrentFrameCount = 0;
92 const char* Sampler::GetDescription() const
97 float Sampler::GetMeanValue() const
100 if( mNumSamples > 0 )
102 meanValue = mAccumulated / (float)mNumSamples;
107 float Sampler::GetStandardDeviation() const
109 float standardDeviation=0.0f;
110 if( mNumSamples > 0 )
112 standardDeviation = sqrtf( mNumSamples * mAccumulatedSquare - (mAccumulated*mAccumulated)) / mNumSamples;
114 return standardDeviation;
117 float Sampler::GetMin() const
122 float Sampler::GetMax() const
127 GlProxyImplementation::GlProxyImplementation(EnvironmentOptions& environmentOptions)
128 : mEnvironmentOptions(environmentOptions),
129 mActiveTextureSampler( "ActiveTexture calls"),
130 mClearSampler("Clear calls"),
131 mBindBufferSampler( "Bind buffers"),
132 mBindTextureSampler( "Bind textures"),
133 mDrawSampler("Draw calls"),
134 mUniformSampler("Uniform sets"),
135 mUseProgramSampler("Used programs"),
142 GlProxyImplementation::~GlProxyImplementation()
146 void GlProxyImplementation::PreRender()
150 void GlProxyImplementation::PostRender( unsigned int timeDelta )
152 // Accumulate counts in each sampler
155 // When we reach the desired frame count, output the averages from the samples
157 if( mFrameCount >= mEnvironmentOptions.GetGlesCallTime() * NUM_FRAMES_PER_SECOND )
164 void GlProxyImplementation::ActiveTexture( GLenum texture )
166 mActiveTextureSampler.Increment();
167 GlImplementation::ActiveTexture(texture);
170 void GlProxyImplementation::Clear( GLbitfield mask )
172 mClearSampler.Increment();
173 GlImplementation::Clear(mask);
176 void GlProxyImplementation::BindBuffer( GLenum target, GLuint buffer )
178 mBindBufferSampler.Increment();
179 GlImplementation::BindBuffer(target,buffer);
182 void GlProxyImplementation::BindTexture( GLenum target, GLuint texture )
184 mBindTextureSampler.Increment();
185 GlImplementation::BindTexture(target,texture);
188 void GlProxyImplementation::DrawArrays( GLenum mode, GLint first, GLsizei count )
190 mDrawSampler.Increment();
191 GlImplementation::DrawArrays(mode,first,count);
194 void GlProxyImplementation::DrawElements( GLenum mode, GLsizei count, GLenum type, const void* indices )
196 mDrawSampler.Increment();
197 GlImplementation::DrawElements(mode,count,type,indices);
200 void GlProxyImplementation::Uniform1f( GLint location, GLfloat x )
202 mUniformSampler.Increment();
203 GlImplementation::Uniform1f(location,x);
206 void GlProxyImplementation::Uniform1fv( GLint location, GLsizei count, const GLfloat* v )
208 mUniformSampler.Increment();
209 GlImplementation::Uniform1fv(location,count,v);
212 void GlProxyImplementation::Uniform1i( GLint location, GLint x )
214 mUniformSampler.Increment();
215 GlImplementation::Uniform1i(location,x);
218 void GlProxyImplementation::Uniform1iv( GLint location, GLsizei count, const GLint* v )
220 mUniformSampler.Increment();
221 GlImplementation::Uniform1iv(location,count,v);
224 void GlProxyImplementation::Uniform2f( GLint location, GLfloat x, GLfloat y)
226 mUniformSampler.Increment();
227 GlImplementation::Uniform2f(location,x,y);
230 void GlProxyImplementation::Uniform2fv( GLint location, GLsizei count, const GLfloat* v )
232 mUniformSampler.Increment();
233 GlImplementation::Uniform2fv(location,count,v);
236 void GlProxyImplementation::Uniform2i( GLint location, GLint x, GLint y )
238 mUniformSampler.Increment();
239 GlImplementation::Uniform2i(location,x,y);
242 void GlProxyImplementation::Uniform2iv( GLint location, GLsizei count, const GLint* v )
244 mUniformSampler.Increment();
245 GlImplementation::Uniform2iv(location,count,v);
248 void GlProxyImplementation::Uniform3f( GLint location, GLfloat x, GLfloat y, GLfloat z)
250 mUniformSampler.Increment();
251 GlImplementation::Uniform3f(location,x,y,z);
254 void GlProxyImplementation::Uniform3fv( GLint location, GLsizei count, const GLfloat* v )
256 mUniformSampler.Increment();
257 GlImplementation::Uniform3fv(location,count,v);
260 void GlProxyImplementation::Uniform3i( GLint location, GLint x, GLint y, GLint z )
262 mUniformSampler.Increment();
263 GlImplementation::Uniform3i(location,x,y,z);
266 void GlProxyImplementation::Uniform3iv( GLint location, GLsizei count, const GLint* v )
268 mUniformSampler.Increment();
269 GlImplementation::Uniform3iv(location,count,v);
272 void GlProxyImplementation::Uniform4f( GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w )
274 mUniformSampler.Increment();
275 GlImplementation::Uniform4f(location,x,y,z,w);
278 void GlProxyImplementation::Uniform4fv( GLint location, GLsizei count, const GLfloat* v )
280 mUniformSampler.Increment();
281 GlImplementation::Uniform4fv(location,count,v);
284 void GlProxyImplementation::Uniform4i( GLint location, GLint x, GLint y, GLint z, GLint w )
286 mUniformSampler.Increment();
287 GlImplementation::Uniform4i(location,x,y,z,w);
290 void GlProxyImplementation::Uniform4iv( GLint location, GLsizei count, const GLint* v )
292 mUniformSampler.Increment();
293 GlImplementation::Uniform4iv(location,count,v);
296 void GlProxyImplementation::UniformMatrix2fv( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value )
298 mUniformSampler.Increment();
299 GlImplementation::UniformMatrix2fv(location,count,transpose,value);
302 void GlProxyImplementation::UniformMatrix3fv( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value )
304 mUniformSampler.Increment();
305 GlImplementation::UniformMatrix3fv(location,count,transpose,value);
308 void GlProxyImplementation::UniformMatrix4fv( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value )
310 mUniformSampler.Increment();
311 GlImplementation::UniformMatrix4fv(location,count,transpose,value);
314 void GlProxyImplementation::UseProgram( GLuint program )
316 mUseProgramSampler.Increment();
317 GlImplementation::UseProgram(program);
320 void GlProxyImplementation::AccumulateSamples()
322 // Accumulate counts in each sampler
323 mActiveTextureSampler.Accumulate();
324 mClearSampler.Accumulate();
325 mBindBufferSampler.Accumulate();
326 mBindTextureSampler.Accumulate();
327 mDrawSampler.Accumulate();
328 mUniformSampler.Accumulate();
329 mUseProgramSampler.Accumulate();
332 void GlProxyImplementation::LogResults()
334 Debug::LogMessage( Debug::DebugInfo, "OpenGL ES statistics sampled over %d frames) operations per frame:\n", mFrameCount );
335 LogCalls( mActiveTextureSampler );
336 LogCalls( mClearSampler );
337 LogCalls( mBindBufferSampler );
338 LogCalls( mBindTextureSampler );
339 LogCalls( mDrawSampler );
340 LogCalls( mUniformSampler );
341 LogCalls( mUseProgramSampler );
344 void GlProxyImplementation::LogCalls( const Sampler& sampler )
346 Debug::LogMessage( Debug::DebugInfo, " %s : Mean %5.2f (Min:%5.2f, Max:%5.2f, StdDev:%5.2f)\n",
347 sampler.GetDescription(),
348 sampler.GetMeanValue(), sampler.GetMin(), sampler.GetMax(),
349 sampler.GetStandardDeviation() );
352 void GlProxyImplementation::ResetSamplers()
354 mActiveTextureSampler.Reset();
355 mClearSampler.Reset();
356 mBindBufferSampler.Reset();
357 mBindTextureSampler.Reset();
358 mDrawSampler.Reset();
359 mUniformSampler.Reset();
360 mUseProgramSampler.Reset();
364 } // namespace Adaptor
366 } // namespace Internal