[DEBUG] correct the FPS error on Android

This commit is contained in:
Edouard DUPIN 2017-06-18 13:57:50 +02:00
parent 35a43e70b8
commit d91a26e294
4 changed files with 14 additions and 6 deletions

View File

@ -12,6 +12,7 @@ import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import android.opengl.GLES20;
import android.opengl.GLSurfaceView;
import android.os.Process;
// import the gale package :
/* no need in same package... */
@ -31,14 +32,17 @@ public class GaleRendererGL implements GLSurfaceView.Renderer
m_galeNative = _galeInstance;
}
public void onSurfaceCreated(GL10 _gl, EGLConfig _config) {
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_DISPLAY);
m_galeNative.renderInit();
}
public void onSurfaceChanged(GL10 _gl, int _w, int _h) {
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_DISPLAY);
m_galeNative.renderResize(_w, _h);
}
public void onDrawFrame(GL10 _gl) {
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_DISPLAY);
m_galeNative.renderDraw();
}
}

View File

@ -633,19 +633,20 @@ bool gale::Context::OS_Draw(bool _displayEveryTime) {
m_simulationFile.filePuts(etk::to_string(_displayEveryTime));
m_simulationFile.filePuts("\n");
}
gale::openGL::threadHasContext();
echrono::Steady currentTime = echrono::Steady::now();
// TODO : Review this ...
// this is to prevent the multiple display at the a high frequency ...
#if (!defined(__TARGET_OS__Android) && !defined(__TARGET_OS__Windows))
#if ( !defined(__TARGET_OS__Windows) \
&& !defined(__TARGET_OS__Android))
if(currentTime - m_previousDisplayTime < echrono::milliseconds(8)) {
std::this_thread::sleep_for(std::chrono::milliseconds(1));
gale::openGL::threadHasNoMoreContext();
return false;
}
#endif
m_previousDisplayTime = currentTime;
gale::openGL::threadHasContext();
// process the events
if (m_displayFps == true) {
m_FpsSystemEvent.tic();

View File

@ -25,6 +25,7 @@ namespace gale {
echrono::Duration m_avg_idle;
echrono::Duration m_max_idle;
echrono::Steady m_ticTime;
echrono::Steady m_lastDrawTime;
bool m_display;
bool m_drawingDone;
const char * m_displayName;
@ -46,7 +47,7 @@ namespace gale {
m_drawingDone(false),
m_displayName(_displayName),
m_displayFPS(_displayFPS) {
m_lastDrawTime = echrono::Steady::now();
}
/**
* @brief Destructor
@ -115,7 +116,9 @@ namespace gale {
<< m_max_idle << " ");
}
if (m_displayFPS == true) {
GALE_PRINT("FPS : " << m_nbDisplayTime << "/" << m_nbCallTime << "fps");
float nbSeconds = (echrono::Steady::now() - m_lastDrawTime).toSeconds();
m_lastDrawTime = echrono::Steady::now();
GALE_PRINT("FPS : " << m_nbDisplayTime << "/" << m_nbCallTime << " frames ==> " << (float(m_nbDisplayTime)/nbSeconds) << "fps");
}
m_max = echrono::Duration(0);
m_min = echrono::Duration(99999999,0);

View File

@ -56,7 +56,7 @@ bool gale::resource::Texture::updateContext() {
//Lock error ==> try later ...
return false;
}
if (false == m_loaded) {
if (m_loaded == false) {
// Request a new texture at openGl :
glGenTextures(1, &m_texId);
}