/// <summary> /// Some message that's only useful in debugging. /// </summary> /// <param name="info">Something incredibly interesting.</param> /// <param name="format">Formatting shizz.</param> public static void v(string info, params object[] format) { if (Verbose) { Log.v(String.Format(info, format)); } }
private void doDeferredOperations() { if (this.TexPointer == 0) { lock (Graphics.RenderLockBlob) { Log.v("Doing deferred texture operation (creation) on " + this.Filename); createNewGlTexture(); } } if (needsDestroy) { doDestroy(); needsDestroy = false; } }
/// <summary> /// Either changes the name of an existing texture (and it's entry in the global /// texture array), or creates a new texture sharing the data of the existing one /// but with a different name. (Bitmap object and GL graphics memory is shared.) /// /// This call is NOT necessary in ordinary usage! EVERY Texture gets put in the global /// texture array once created, even if the name assigned is just a Guid. /// </summary> /// <param name="name"></param> /// <param name="texture"></param> /// <param name="makeCopy"></param> /// <remarks>ALL Textures already exist in the global texture array! /// This call is NOT necessary in ordinary Texture usage! /// Textures created using the new Texture(Bitmap) constructor have a GUID assigned.</remarks> public static void SetTexture(string name, Texture texture, bool makeCopy) { name = name.ToLower(); lock (textures) { Texture t; if (makeCopy) { // Copy the bastard, and change the name. t = new Texture(); t.bitmap = texture.bitmap; t.TexPointer = texture.TexPointer; t.Filename = name; if (textures.Keys.Contains(name)) { Log.w("A texture with name '" + name + "' is already present - replacing."); textures.Remove(name); } } else { textures.Remove(texture.Filename); texture.Filename = name; t = texture; } if (textures.ContainsKey(name)) { textures.Remove(name); Log.v("Replacing texture '" + name + "' with new one. This is rarely" + " a good thing."); } textures.Add(name, t); } }
private static Bitmap ChromaKeyIfNecessary(Bitmap bmp, bool treatAsIndexed) { if (treatAsIndexed || (bmp.PixelFormat & PixelFormat.Indexed) == PixelFormat.Indexed) { if (treatAsIndexed) { Log.v("treatAsIndexed=true"); } Log.v("Got an indexed bitmap. Doing chroma-keying with zelda-pink chroma. (225,0,126)"); Bitmap bmpNew = ConvertTo32bppBitmap(bmp); bmp.Dispose(); bmp = bmpNew; ChromaKey32bppBitmap(bmp, Color.FromArgb(225, 0, 126)); return(bmp); } // If 24bpp, chroma-key based on pixel at coords (0,0) (top-left) if (!((bmp.PixelFormat & PixelFormat.Alpha) == PixelFormat.Alpha)) { DateTime dtConvStart = DateTime.Now; // ah. chroma-keying time! what fun. Bitmap bmpNew = ConvertTo32bppBitmap(bmp); bmp.Dispose(); bmp = bmpNew; ChromaKey32bppBitmap(bmp, bmp.GetPixel(0, 0)); DateTime dtConvEnd = DateTime.Now; Log.i("Bitmap chroma-keying of bitmap of size " + bmp.Size.ToString() + " took " + (dtConvEnd - dtConvStart).TotalMilliseconds.ToString() + "ms."); } return(bmp); }
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(); }