void TextureThread() { PendingTextures.Open(); Logger.DebugLog("Started Texture Thread"); while (TextureThreadRunning) { TextureLoadItem item = null; if (!PendingTextures.Dequeue(Timeout.Infinite, ref item)) { continue; } if (TexturesPtrMap.ContainsKey(item.TeFace.TextureID)) { item.Data.TextureInfo = TexturesPtrMap[item.TeFace.TextureID]; continue; } if (LoadTexture(item.TeFace.TextureID, ref item.Data.TextureInfo.Texture, false)) { Bitmap bitmap = (Bitmap)item.Data.TextureInfo.Texture; bool hasAlpha; if (item.Data.TextureInfo.Texture.PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppArgb) { hasAlpha = true; } else { hasAlpha = false; } item.Data.TextureInfo.HasAlpha = hasAlpha; bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY); var loadOnMainThread = new MethodInvoker(() => { item.Data.TextureInfo.TexturePointer = RHelp.GLLoadImage(bitmap, hasAlpha, RenderSettings.HasMipmap); TexturesPtrMap[item.TeFace.TextureID] = item.Data.TextureInfo; bitmap.Dispose(); item.Data.TextureInfo.Texture = null; SafeInvalidate(); }); if (!instance.MonoRuntime || IsHandleCreated) { BeginInvoke(loadOnMainThread); } } } Logger.DebugLog("Texture thread exited"); }
void PrepareText(TextItem item) { // If we're modified and have texture already delete it from graphics card if (item.TextureID > 0) { //GL.DeleteTexture(item.TextureID); item.TextureID = -1; } Size s; try { s = TextRenderer.MeasureText( item.Text, item.Font, MaxSize, item.Flags); } catch { return; } item.ImgWidth = s.Width; item.ImgHeight = s.Height; if (!RenderSettings.TextureNonPowerOfTwoSupported) { item.ImgWidth = RHelp.NextPow2(s.Width); item.ImgHeight = RHelp.NextPow2(s.Height); } Bitmap img = new Bitmap( item.ImgWidth, item.ImgHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(img); g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit; TextRenderer.DrawText( g, item.Text, item.Font, new Rectangle(0, 0, s.Width + 2, s.Height + 2), Color.White, Color.Transparent, item.Flags); item.TextureID = RHelp.GLLoadImage(img, true, false); g.Dispose(); img.Dispose(); }
void InitWater() { Bitmap normal = (Bitmap)Bitmap.FromFile(System.IO.Path.Combine("shader_data", "normalmap.png")); reflectionTexture = RHelp.GLLoadImage(normal, false); refractionTexture = RHelp.GLLoadImage(normal, false); normalmap = RHelp.GLLoadImage(normal, false); depthTexture = RHelp.GLLoadImage(normal, false); dudvmap = RHelp.GLLoadImage((Bitmap)Bitmap.FromFile(System.IO.Path.Combine("shader_data", "dudvmap.png")), false); waterProgram.Load("water.vert", "water.frag"); }
public void PrepareText(int maxWidth) { if (maxWidth != widthForTextureGenerated) { string txt = item.From + item.Text; // If we're modified and have texture already delete it from graphics card if (textureID > 0) { GL.DeleteTexture(textureID); textureID = -1; } TextFormatFlags flags = TextFormatFlags.Top | TextFormatFlags.Left | TextFormatFlags.WordBreak; Size s = TextRenderer.MeasureText( txt, ChatOverlay.ChatFont, new Size(maxWidth, 2000), flags); ImgWidth = TextWidth = s.Width; ImgHeight = TextHeight = s.Height; if (!RenderSettings.TextureNonPowerOfTwoSupported) { ImgWidth = RHelp.NextPow2(TextWidth); ImgHeight = RHelp.NextPow2(TextHeight); } Bitmap img = new Bitmap( ImgWidth, ImgHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(img); TextRenderer.DrawText( g, txt, ChatOverlay.ChatFont, new Rectangle(0, ImgHeight - TextHeight, TextWidth + 2, TextHeight + 2), Color.White, Color.Transparent, flags); widthForTextureGenerated = maxWidth; textureID = RHelp.GLLoadImage(img, true, false); g.Dispose(); img.Dispose(); } }
public override void Render(RenderPass pass, int pickingID, SceneWindow scene, float time) { terrainTimeSinceUpdate += time; if (Modified && terrainTimeSinceUpdate > RenderSettings.MinimumTimeBetweenTerrainUpdated) { if (!terrainInProgress) { terrainInProgress = true; ResetTerrain(false); UpdateTerrain(); } } if (terrainTextureNeedsUpdate) { UpdateTerrainTexture(); } if (terrainIndices == null || terrainVertices == null) { return; } GL.Color3(1f, 1f, 1f); GL.EnableClientState(ArrayCap.VertexArray); GL.EnableClientState(ArrayCap.TextureCoordArray); GL.EnableClientState(ArrayCap.NormalArray); if (pass == RenderPass.Picking) { GL.EnableClientState(ArrayCap.ColorArray); GL.ShadeModel(ShadingModel.Flat); } if (terrainImage != null) { if (terrainTexture != -1) { GL.DeleteTexture(terrainTexture); } terrainTexture = RHelp.GLLoadImage(terrainImage, false); terrainImage.Dispose(); terrainImage = null; } if (pass != RenderPass.Picking && terrainTexture != -1) { GL.Enable(EnableCap.Texture2D); GL.BindTexture(TextureTarget.Texture2D, terrainTexture); } if (!RenderSettings.UseVBO || terrainVBOFailed) { unsafe { fixed(float *normalPtr = &terrainVertices[0].Vertex.Normal.X) fixed(float *texPtr = &terrainVertices[0].Vertex.TexCoord.X) fixed(byte *colorPtr = &terrainVertices[0].Color.R) { GL.NormalPointer(NormalPointerType.Float, ColorVertex.Size, (IntPtr)normalPtr); GL.TexCoordPointer(2, TexCoordPointerType.Float, ColorVertex.Size, (IntPtr)texPtr); GL.VertexPointer(3, VertexPointerType.Float, ColorVertex.Size, terrainVertices); if (pass == RenderPass.Picking) { GL.ColorPointer(4, ColorPointerType.UnsignedByte, ColorVertex.Size, (IntPtr)colorPtr); } GL.DrawElements(BeginMode.Triangles, terrainIndices.Length, DrawElementsType.UnsignedInt, terrainIndices); } } } else { if (terrainVBO == -1) { Compat.GenBuffers(out terrainVBO); Compat.BindBuffer(BufferTarget.ArrayBuffer, terrainVBO); Compat.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(terrainVertices.Length * ColorVertex.Size), terrainVertices, BufferUsageHint.StaticDraw); if (Compat.BufferSize(BufferTarget.ArrayBuffer) != terrainVertices.Length * ColorVertex.Size) { terrainVBOFailed = true; Compat.BindBuffer(BufferTarget.ArrayBuffer, 0); terrainVBO = -1; } } else { Compat.BindBuffer(BufferTarget.ArrayBuffer, terrainVBO); } if (terrainIndexVBO == -1) { Compat.GenBuffers(out terrainIndexVBO); Compat.BindBuffer(BufferTarget.ElementArrayBuffer, terrainIndexVBO); Compat.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(terrainIndices.Length * sizeof(uint)), terrainIndices, BufferUsageHint.StaticDraw); if (Compat.BufferSize(BufferTarget.ElementArrayBuffer) != terrainIndices.Length * sizeof(uint)) { terrainVBOFailed = true; Compat.BindBuffer(BufferTarget.ElementArrayBuffer, 0); terrainIndexVBO = -1; } } else { Compat.BindBuffer(BufferTarget.ElementArrayBuffer, terrainIndexVBO); } if (!terrainVBOFailed) { GL.NormalPointer(NormalPointerType.Float, ColorVertex.Size, (IntPtr)12); GL.TexCoordPointer(2, TexCoordPointerType.Float, ColorVertex.Size, (IntPtr)(24)); if (pass == RenderPass.Picking) { GL.ColorPointer(4, ColorPointerType.UnsignedByte, ColorVertex.Size, (IntPtr)32); } GL.VertexPointer(3, VertexPointerType.Float, ColorVertex.Size, (IntPtr)(0)); GL.DrawElements(BeginMode.Triangles, terrainIndices.Length, DrawElementsType.UnsignedInt, IntPtr.Zero); } Compat.BindBuffer(BufferTarget.ArrayBuffer, 0); Compat.BindBuffer(BufferTarget.ElementArrayBuffer, 0); } if (pass == RenderPass.Picking) { GL.DisableClientState(ArrayCap.ColorArray); GL.ShadeModel(ShadingModel.Smooth); } else { GL.BindTexture(TextureTarget.Texture2D, 0); } GL.DisableClientState(ArrayCap.VertexArray); GL.DisableClientState(ArrayCap.TextureCoordArray); GL.DisableClientState(ArrayCap.NormalArray); }