diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index 3f9727f4..3a8989e1 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -42,9 +42,10 @@ namespace Vocaluxe.Lib.Draw } } - class CD3DTexture:CTextureBase,IDisposable + class CD3DTexture : CTextureBase, IDisposable { public readonly Texture D3DTexture; + public CD3DTexture(Device device, Size dataSize, int texWidth = 0, int texHeight = 0) : base(dataSize, texWidth, texHeight) { D3DTexture = new Texture(device, W2, H2, 0, Usage.AutoGenerateMipMap, Format.A8R8G8B8, Pool.Managed); @@ -52,7 +53,7 @@ namespace Vocaluxe.Lib.Draw public void Dispose() { - if(D3DTexture.Disposed) + if (D3DTexture.Disposed) throw new ObjectDisposedException(GetType().Name); D3DTexture.Dispose(); RefCount = 0; @@ -482,7 +483,7 @@ namespace Vocaluxe.Lib.Draw /// public CTextureRef CopyScreen() { - var tex = _CreateTexture(new Size(_W, _H)); + CD3DTexture tex = _CreateTexture(new Size(_W, _H)); Surface backbufferSurface = _Device.GetBackBuffer(0, 0); Surface textureSurface = tex.D3DTexture.GetSurfaceLevel(0); Surface.FromSurface(textureSurface, backbufferSurface, Filter.Default, 0, new Rectangle(0, 0, _W, _H), new Rectangle(0, 0, _W, _H)); @@ -630,7 +631,7 @@ namespace Vocaluxe.Lib.Draw return false; // Texture memory to big texture.DataSize = new Size(w, h); } - _WriteDataToTexture(texture.D3DTexture, w, data); + _WriteDataToTexture(texture.D3DTexture, w, data); return true; } diff --git a/Vocaluxe/Lib/Draw/CDrawBase.cs b/Vocaluxe/Lib/Draw/CDrawBase.cs index 3d56f265..9ab6ae89 100644 --- a/Vocaluxe/Lib/Draw/CDrawBase.cs +++ b/Vocaluxe/Lib/Draw/CDrawBase.cs @@ -396,33 +396,17 @@ namespace Vocaluxe.Lib.Draw return true; } - /// - /// Checks if a texture exists - /// - /// The texture to check - /// True if the texture exists - protected bool _TextureExists(CTextureRef texture) - { - TTextureType t; - return _GetTexture(texture, out t); - } - - protected TTextureType _GetTexture(CTextureRef textureRef) - { - if (textureRef == null) - return null; - TTextureType texture; - lock (_Textures) - { - _Textures.TryGetValue(textureRef.ID, out texture); - } - return texture; - } - protected bool _GetTexture(CTextureRef textureRef, out TTextureType texture) { - texture = _GetTexture(textureRef); - return texture != null; + if (textureRef == null) + { + texture = null; + return false; + } + lock (_Textures) + { + return _Textures.TryGetValue(textureRef.ID, out texture) && texture!=null; + } } /// diff --git a/Vocaluxe/Lib/Draw/COpenGL.cs b/Vocaluxe/Lib/Draw/COpenGL.cs index 29e5b82b..8e94d484 100644 --- a/Vocaluxe/Lib/Draw/COpenGL.cs +++ b/Vocaluxe/Lib/Draw/COpenGL.cs @@ -21,7 +21,6 @@ using OpenTK.Graphics; using System; using System.Drawing; using System.IO; -using System.Runtime.InteropServices; using System.Windows.Forms; using Vocaluxe.Base; using VocaluxeLib; @@ -29,9 +28,6 @@ using VocaluxeLib.Draw; using BeginMode = OpenTK.Graphics.OpenGL.BeginMode; using BlendingFactorDest = OpenTK.Graphics.OpenGL.BlendingFactorDest; using BlendingFactorSrc = OpenTK.Graphics.OpenGL.BlendingFactorSrc; -using BufferAccess = OpenTK.Graphics.OpenGL.BufferAccess; -using BufferTarget = OpenTK.Graphics.OpenGL.BufferTarget; -using BufferUsageHint = OpenTK.Graphics.OpenGL.BufferUsageHint; using ClearBufferMask = OpenTK.Graphics.OpenGL.ClearBufferMask; using DepthFunction = OpenTK.Graphics.OpenGL.DepthFunction; using EnableCap = OpenTK.Graphics.OpenGL.EnableCap; @@ -60,15 +56,14 @@ namespace Vocaluxe.Lib.Draw } } - class COGLTexture : CTextureBase,IDisposable + class COGLTexture : CTextureBase, IDisposable { - public int PBO; //The texture "name" according to the specs public readonly int Name; private bool _IsDisposed; - public COGLTexture( int name, Size dataSize, int texWidth = 0, int texHeight = 0) : base(dataSize, texWidth, texHeight) + public COGLTexture(int name, Size dataSize, int texWidth = 0, int texHeight = 0) : base(dataSize, texWidth, texHeight) { Name = name; } @@ -79,8 +74,6 @@ namespace Vocaluxe.Lib.Draw throw new ObjectDisposedException(GetType().Name); _IsDisposed = true; GL.DeleteTexture(Name); - if (PBO > 0) - GL.DeleteBuffers(1, ref PBO); RefCount = 0; } } @@ -89,7 +82,6 @@ namespace Vocaluxe.Lib.Draw { #region private vars private readonly GLControl _Control; - private bool _UsePBO; #endregion private vars public COpenGL() @@ -284,7 +276,7 @@ namespace Vocaluxe.Lib.Draw GL.BindTexture(TextureTarget.Texture2D, texture.Name); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, texture.W2, texture.H2, 0, PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero); - GL.CopyTexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, 0, 0, size.Width,size.Height);//TODO: Use _X,_Y and _W,_H? + GL.CopyTexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, 0, 0, size.Width, size.Height); //TODO: Use _X,_Y and _W,_H? GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); @@ -426,7 +418,6 @@ namespace Vocaluxe.Lib.Draw GL.BindTexture(TextureTarget.Texture2D, texture.Name); - GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, texture.W2, texture.H2, 0, PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero); GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, texture.DataSize.Width, texture.DataSize.Height, PixelFormat.Bgra, PixelType.UnsignedByte, data); @@ -444,22 +435,6 @@ namespace Vocaluxe.Lib.Draw { COGLTexture texture = _CreateTexture(dataSize); - if (_UsePBO) - { - try - { - GL.GenBuffers(1, out texture.PBO); - GL.BindBuffer(BufferTarget.PixelUnpackBuffer, texture.PBO); - GL.BufferData(BufferTarget.PixelUnpackBuffer, (IntPtr)data.Length, IntPtr.Zero, BufferUsageHint.StreamDraw); - GL.BindBuffer(BufferTarget.PixelUnpackBuffer, 0); - } - catch (Exception e) - { - CLog.LogError("PBO creation failed. Using fallback solution.", false, false, e); - _UsePBO = false; - } - } - GL.BindTexture(TextureTarget.Texture2D, texture.Name); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, texture.W2, texture.H2, 0, PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero); @@ -480,7 +455,7 @@ namespace Vocaluxe.Lib.Draw public override bool UpdateTexture(CTextureRef textureRef, int w, int h, byte[] data) { COGLTexture texture; - if (_GetTexture(textureRef,out texture)) + if (_GetTexture(textureRef, out texture)) return false; if (texture.DataSize.Width != w || texture.DataSize.Height != h) { @@ -491,27 +466,6 @@ namespace Vocaluxe.Lib.Draw texture.DataSize = new Size(w, h); } - if (_UsePBO) - { - GL.BindBuffer(BufferTarget.PixelUnpackBuffer, texture.PBO); - - IntPtr buffer = GL.MapBuffer(BufferTarget.PixelUnpackBuffer, BufferAccess.WriteOnly); - Marshal.Copy(data, 0, buffer, data.Length); - - GL.UnmapBuffer(BufferTarget.PixelUnpackBuffer); - - GL.BindTexture(TextureTarget.Texture2D, texture.Name); - - GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, w, h, PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero); - - GL.Ext.GenerateMipmap(GenerateMipmapTarget.Texture2D); - - GL.BindTexture(TextureTarget.Texture2D, 0); - GL.BindBuffer(BufferTarget.PixelUnpackBuffer, 0); - - return true; - } - GL.BindTexture(TextureTarget.Texture2D, texture.Name); GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, w, h, PixelFormat.Bgra, PixelType.UnsignedByte, data);