private static int chkt = 0; // used so we don't update the FPS reading constantly
public static void Render()
{
DateTime dtStart = DateTime.Now;
// Gl blah blah
lock (RenderLockBlob)
{
int gerr = Gl.glGetError();
if (gerr != 0)
{
Log.w("glGetError():: " + Glu.gluErrorString(gerr));
}
// How inefficient is this?
// (not rhetorical question, seriously -- does it matter?)
int WindowWidth, WindowHeight;
Glfw.glfwGetWindowSize(out WindowWidth, out WindowHeight);
Gl.glViewport(0, 0, WindowWidth, WindowHeight);
// clear background (no, really?)
Gl.glClearColor(((float)backgroundColor.R) / 255f,
((float)backgroundColor.G / 255f),
((float)backgroundColor.B / 255f), ((float)backgroundColor.A / 255f));
Gl.glClearDepth(double.MinValue);
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
// Set-up the modelview matrix again.
Gl.glMatrixMode(Gl.GL_MODELVIEW);
Gl.glLoadIdentity();
Gl.glScalef(Camera.Zoom, Camera.Zoom, 1f);
Gl.glTranslatef(-Camera.Position.X, -Camera.Position.Y, 0f);
Gl.glRotatef(-Camera.Angle, 0f, 0f, 1f);
lock (Renderables)
{
Texture.DoDeferredTextureOperations();
// ...Because depth testing can't cut it with alpha blending. :(
if (renderableListNeedsSorting)
{
Log.v("SORTING.");
renderableListNeedsSorting = false;
DateTime dtSortStart = DateTime.Now;
Renderables.Sort(new Comparison <Renderable>(compareRenderablesDepths));
Log.v("R.Sort took " + (DateTime.Now - dtSortStart).TotalMilliseconds.ToString()
+ "ms.");
// Unsurprisingly, this operation can get slow. :p
// Could write an O(n) version, cba!
if (PerformSlowDebugDepthChecking)
{
DateTime dtCheckStart = DateTime.Now;
foreach (Renderable r1 in Renderables)
{
foreach (Renderable r2 in Renderables)
{
checkForDepthProblems(r1, r2);
}
}
Log.v("checkForDepthProblems took " + (DateTime.Now - dtCheckStart)
.TotalMilliseconds.ToString() + "ms.");
}
}
foreach (Renderable r in Renderables)
{
r.Render();
}
}
Glfw.glfwSwapBuffers();
Glfw.glfwPollEvents();
DateTime dtEnd = DateTime.Now;
chkt++;
if (chkt >= 60)
{
chkt = 0;
//Log.i((dtEnd - dtStart).TotalMilliseconds.ToString() + "ms to render");
}
//Thread.Sleep(EatCPU ? 0 : 30);
}
// This is here, as we don't want a callback and the loop trying to lock stuff.
// Run stuff that needs to be in graphics thread
//handleCallbacks();
}