namespace Adaptor
{
-Sampler::Sampler()
-: mAccumulated(0.0f),
+Sampler::Sampler( const char* description )
+: mDescription( description ),
+ mAccumulated(0.0f),
mAccumulatedSquare(0.0f),
mMin(0.0f),
mMax(0.0f),
- mNumSamples(0)
+ mNumSamples(0),
+ mCurrentFrameCount(0)
{
}
+void Sampler::Increment()
+{
+ mCurrentFrameCount++;
+}
void Sampler::Reset()
{
mMin = 0.0f;
mMax = 0.0f;
mNumSamples = 0;
+ mCurrentFrameCount = 0;
}
-void Sampler::Accumulate(float value)
+void Sampler::Accumulate()
{
if( mNumSamples == 0 )
{
- mMin = value;
- mMax = value;
+ mMin = mCurrentFrameCount;
+ mMax = mCurrentFrameCount;
}
else
{
- if(value < mMin)
+ if(mCurrentFrameCount < mMin)
{
- mMin = value;
+ mMin = mCurrentFrameCount;
}
- if(value > mMax)
+ if(mCurrentFrameCount > mMax)
{
- mMax = value;
+ mMax = mCurrentFrameCount;
}
}
mNumSamples++;
- mAccumulated += value;
- mAccumulatedSquare += (value * value);
+ mAccumulated += mCurrentFrameCount;
+ mAccumulatedSquare += (mCurrentFrameCount * mCurrentFrameCount);
+ mCurrentFrameCount = 0;
+}
+const char* Sampler::GetDescription() const
+{
+ return mDescription;
}
-float Sampler::GetMeanValue()
+float Sampler::GetMeanValue() const
{
float meanValue = 0;
if( mNumSamples > 0 )
return meanValue;
}
-float Sampler::GetStandardDeviation()
+float Sampler::GetStandardDeviation() const
{
float standardDeviation=0.0f;
if( mNumSamples > 0 )
return standardDeviation;
}
-float Sampler::GetMin()
+float Sampler::GetMin() const
{
return mMin;
}
-float Sampler::GetMax()
+float Sampler::GetMax() const
{
return mMax;
}
GlProxyImplementation::GlProxyImplementation(EnvironmentOptions& environmentOptions)
: mEnvironmentOptions(environmentOptions),
+ mClearSampler("Clear calls"),
+ mBindBufferSampler( "Bind buffers"),
+ mBindTextureSampler( "Bind textures"),
+ mDrawSampler("Draw calls"),
+ mUniformSampler("Uniform sets"),
+ mUseProgramSampler("Used programs"),
mDrawCount(0),
+ mUniformCount(0),
mFrameCount(0)
{
}
void GlProxyImplementation::PostRender( unsigned int timeDelta )
{
// Accumulate counts in each sampler
- mDrawSampler.Accumulate(mDrawCount);
- mDrawCount=0;
+ AccumulateSamples();
// When we reach the desired frame count, output the averages from the samples
mFrameCount++;
if( mFrameCount >= mEnvironmentOptions.GetGlesCallTime() * NUM_FRAMES_PER_SECOND )
{
- Debug::LogMessage( Debug::DebugInfo, "Mean number of draw calls per frame: %5.2f (Min:%5.2f, Max:%5.2f, StdDev:%5.2f sampled over %d frames\n",
- mDrawSampler.GetMeanValue(),
- mDrawSampler.GetMin(),
- mDrawSampler.GetMax(),
- mDrawSampler.GetStandardDeviation(),
- mFrameCount );
-
- mDrawSampler.Reset();
- mFrameCount = 0;
+ LogResults();
+ ResetSamplers();
}
}
-void GlProxyImplementation::DrawArrays (GLenum mode, GLint first, GLsizei count)
+void GlProxyImplementation::Clear( GLbitfield mask )
+{
+ mClearSampler.Increment();
+ GlImplementation::Clear(mask);
+}
+
+void GlProxyImplementation::BindBuffer( GLenum target, GLuint buffer )
+{
+ mBindBufferSampler.Increment();
+ GlImplementation::BindBuffer(target,buffer);
+}
+
+void GlProxyImplementation::BindTexture( GLenum target, GLuint texture )
+{
+ mBindTextureSampler.Increment();
+ GlImplementation::BindTexture(target,texture);
+}
+
+void GlProxyImplementation::DrawArrays( GLenum mode, GLint first, GLsizei count )
{
- mDrawCount++;
+ mDrawSampler.Increment();
GlImplementation::DrawArrays(mode,first,count);
}
-void GlProxyImplementation::DrawElements (GLenum mode, GLsizei count, GLenum type, const void* indices)
+void GlProxyImplementation::DrawElements( GLenum mode, GLsizei count, GLenum type, const void* indices )
{
- mDrawCount++;
+ mDrawSampler.Increment();
GlImplementation::DrawElements(mode,count,type,indices);
}
+void GlProxyImplementation::Uniform1f( GLint location, GLfloat x )
+{
+ mUniformSampler.Increment();
+ GlImplementation::Uniform1f(location,x);
+}
+
+void GlProxyImplementation::Uniform1fv( GLint location, GLsizei count, const GLfloat* v )
+{
+ mUniformSampler.Increment();
+ GlImplementation::Uniform1fv(location,count,v);
+}
+
+void GlProxyImplementation::Uniform1i( GLint location, GLint x )
+{
+ mUniformSampler.Increment();
+ GlImplementation::Uniform1i(location,x);
+}
+
+void GlProxyImplementation::Uniform1iv( GLint location, GLsizei count, const GLint* v )
+{
+ mUniformSampler.Increment();
+ GlImplementation::Uniform1iv(location,count,v);
+}
+
+void GlProxyImplementation::Uniform2f( GLint location, GLfloat x, GLfloat y)
+{
+ mUniformSampler.Increment();
+ GlImplementation::Uniform2f(location,x,y);
+}
+
+void GlProxyImplementation::Uniform2fv( GLint location, GLsizei count, const GLfloat* v )
+{
+ mUniformSampler.Increment();
+ GlImplementation::Uniform2fv(location,count,v);
+}
+
+void GlProxyImplementation::Uniform2i( GLint location, GLint x, GLint y )
+{
+ mUniformSampler.Increment();
+ GlImplementation::Uniform2i(location,x,y);
+}
+
+void GlProxyImplementation::Uniform2iv( GLint location, GLsizei count, const GLint* v )
+{
+ mUniformSampler.Increment();
+ GlImplementation::Uniform2iv(location,count,v);
+}
+
+void GlProxyImplementation::Uniform3f( GLint location, GLfloat x, GLfloat y, GLfloat z)
+{
+ mUniformSampler.Increment();
+ GlImplementation::Uniform3f(location,x,y,z);
+}
+
+void GlProxyImplementation::Uniform3fv( GLint location, GLsizei count, const GLfloat* v )
+{
+ mUniformSampler.Increment();
+ GlImplementation::Uniform3fv(location,count,v);
+}
+
+void GlProxyImplementation::Uniform3i( GLint location, GLint x, GLint y, GLint z )
+{
+ mUniformSampler.Increment();
+ GlImplementation::Uniform3i(location,x,y,z);
+}
+
+void GlProxyImplementation::Uniform3iv( GLint location, GLsizei count, const GLint* v )
+{
+ mUniformSampler.Increment();
+ GlImplementation::Uniform3iv(location,count,v);
+}
+
+void GlProxyImplementation::Uniform4f( GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w )
+{
+ mUniformSampler.Increment();
+ GlImplementation::Uniform4f(location,x,y,z,w);
+}
+
+void GlProxyImplementation::Uniform4fv( GLint location, GLsizei count, const GLfloat* v )
+{
+ mUniformSampler.Increment();
+ GlImplementation::Uniform4fv(location,count,v);
+}
+
+void GlProxyImplementation::Uniform4i( GLint location, GLint x, GLint y, GLint z, GLint w )
+{
+ mUniformSampler.Increment();
+ GlImplementation::Uniform4i(location,x,y,z,w);
+}
+
+void GlProxyImplementation::Uniform4iv( GLint location, GLsizei count, const GLint* v )
+{
+ mUniformSampler.Increment();
+ GlImplementation::Uniform4iv(location,count,v);
+}
+
+void GlProxyImplementation::UniformMatrix2fv( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value )
+{
+ mUniformSampler.Increment();
+ GlImplementation::UniformMatrix2fv(location,count,transpose,value);
+}
+
+void GlProxyImplementation::UniformMatrix3fv( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value )
+{
+ mUniformSampler.Increment();
+ GlImplementation::UniformMatrix3fv(location,count,transpose,value);
+}
+
+void GlProxyImplementation::UniformMatrix4fv( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value )
+{
+ mUniformSampler.Increment();
+ GlImplementation::UniformMatrix4fv(location,count,transpose,value);
+}
+
+void GlProxyImplementation::UseProgram( GLuint program )
+{
+ mUseProgramSampler.Increment();
+ GlImplementation::UseProgram(program);
+}
+
+void GlProxyImplementation::AccumulateSamples()
+{
+ // Accumulate counts in each sampler
+ mClearSampler.Accumulate();
+ mBindBufferSampler.Accumulate();
+ mBindTextureSampler.Accumulate();
+ mDrawSampler.Accumulate();
+ mUniformSampler.Accumulate();
+ mUseProgramSampler.Accumulate();
+}
+
+void GlProxyImplementation::LogResults()
+{
+ Debug::LogMessage( Debug::DebugInfo, "OpenGL ES statistics sampled over %d frames) operations per frame:\n", mFrameCount );
+ LogCalls( mClearSampler );
+ LogCalls( mBindBufferSampler );
+ LogCalls( mBindTextureSampler );
+ LogCalls( mDrawSampler );
+ LogCalls( mUniformSampler );
+ LogCalls( mUseProgramSampler );
+}
+
+void GlProxyImplementation::LogCalls( const Sampler& sampler )
+{
+ Debug::LogMessage( Debug::DebugInfo, " %s : Mean %5.2f (Min:%5.2f, Max:%5.2f, StdDev:%5.2f)\n",
+ sampler.GetDescription(),
+ sampler.GetMeanValue(), sampler.GetMin(), sampler.GetMax(),
+ sampler.GetStandardDeviation() );
+}
+
+void GlProxyImplementation::ResetSamplers()
+{
+ mClearSampler.Reset();
+ mBindBufferSampler.Reset();
+ mBindTextureSampler.Reset();
+ mDrawSampler.Reset();
+ mUniformSampler.Reset();
+ mUseProgramSampler.Reset();
+ mFrameCount = 0;
+}
+
} // namespace Adaptor
} // namespace Internal
{
class EnvironmentOptions;
-
+/**
+ * Helper class to calculate the statistics for Open GLES calls
+ */
class Sampler
{
public:
- Sampler();
+
+ /**
+ * Constructor
+ * @param description to write to the log
+ */
+ Sampler( const char* description );
+
+ /**
+ * Increment the counter for this frame
+ */
+ void Increment();
+
+ /**
+ * Reset the counter
+ */
void Reset();
- void Accumulate(float value);
- float GetMeanValue();
- float GetStandardDeviation();
- float GetMin();
- float GetMax();
-private:
+ /**
+ * Accumulate the count onto statistics
+ */
+ void Accumulate();
+
+ /**
+ * @return the description of the sampler
+ */
+ const char* GetDescription() const;
+
+ /**
+ * @return the mean value
+ */
+ float GetMeanValue() const;
+
+ /**
+ * @return the standard deviation
+ */
+ float GetStandardDeviation() const;
+
+ /**
+ * @return the minimum value
+ */
+ float GetMin() const;
+
+ /**
+ * @return the maximum value
+ */
+ float GetMax() const;
+
+private: // Data
+
+ const char* mDescription;
float mAccumulated;
float mAccumulatedSquare;
float mMin;
float mMax;
- int mNumSamples;
+ unsigned int mNumSamples;
+ unsigned int mCurrentFrameCount;
};
/**
class GlProxyImplementation : public GlImplementation
{
public:
+
+ /**
+ * Constructor
+ * @param environmentOptions to check how often to log results
+ */
GlProxyImplementation(EnvironmentOptions& environmentOptions);
+ /**
+ * Virtual destructor
+ */
virtual ~GlProxyImplementation();
+ /**
+ * @copydoc GlAbstraction::PreRender();
+ */
virtual void PreRender();
+ /**
+ * @copydoc GlAbstraction::PostRender();
+ */
virtual void PostRender( unsigned int timeDelta );
- virtual void DrawArrays (GLenum mode, GLint first, GLsizei count);
+ /* OpenGL ES 2.0 API */
+ virtual void Clear( GLbitfield mask );
+
+ virtual void BindBuffer( GLenum target, GLuint buffer );
+ virtual void BindTexture( GLenum target, GLuint texture );
+
+ virtual void DrawArrays( GLenum mode, GLint first, GLsizei count );
+ virtual void DrawElements( GLenum mode, GLsizei count, GLenum type, const void* indices );
+
+ virtual void Uniform1f ( GLint location, GLfloat x );
+ virtual void Uniform1fv( GLint location, GLsizei count, const GLfloat* v );
+ virtual void Uniform1i ( GLint location, GLint x );
+ virtual void Uniform1iv( GLint location, GLsizei count, const GLint* v );
+ virtual void Uniform2f ( GLint location, GLfloat x, GLfloat y );
+ virtual void Uniform2fv( GLint location, GLsizei count, const GLfloat* v );
+ virtual void Uniform2i ( GLint location, GLint x, GLint y );
+ virtual void Uniform2iv( GLint location, GLsizei count, const GLint* v );
+ virtual void Uniform3f ( GLint location, GLfloat x, GLfloat y, GLfloat z );
+ virtual void Uniform3fv( GLint location, GLsizei count, const GLfloat* v );
+ virtual void Uniform3i ( GLint location, GLint x, GLint y, GLint z );
+ virtual void Uniform3iv( GLint location, GLsizei count, const GLint* v );
+ virtual void Uniform4f ( GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w );
+ virtual void Uniform4fv( GLint location, GLsizei count, const GLfloat* v );
+ virtual void Uniform4i ( GLint location, GLint x, GLint y, GLint z, GLint w );
+ virtual void Uniform4iv( GLint location, GLsizei count, const GLint* v );
+ virtual void UniformMatrix2fv( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value );
+ virtual void UniformMatrix3fv( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value );
+ virtual void UniformMatrix4fv( GLint location, GLsizei count, GLboolean transpose, const GLfloat* value );
+
+ virtual void UseProgram( GLuint program );
+
+private: // Helpers
+
+ void AccumulateSamples();
+ void LogResults();
+ void LogCalls( const Sampler& sampler );
+ void ResetSamplers();
+
+private: // Data
- virtual void DrawElements (GLenum mode, GLsizei count, GLenum type, const void* indices);
-
-private:
EnvironmentOptions& mEnvironmentOptions;
+ Sampler mClearSampler;
+ Sampler mBindBufferSampler;
+ Sampler mBindTextureSampler;
Sampler mDrawSampler;
+ Sampler mUniformSampler;
+ Sampler mUseProgramSampler;
int mDrawCount;
+ int mUniformCount;
int mFrameCount;
+
};
} // namespace Adaptor