diff --git a/Vocaluxe/Base/CVideo.cs b/Vocaluxe/Base/CVideo.cs index 597a0f22..0c24177c 100644 --- a/Vocaluxe/Base/CVideo.cs +++ b/Vocaluxe/Base/CVideo.cs @@ -166,6 +166,8 @@ namespace Vocaluxe.Base CVideo.GetFrame(_VideoStream, ref _VideoTexture, videoTime, out videoTime); } + if (_VideoTexture == null) + return; RectangleF bounds = new RectangleF(0f, 0f, CSettings.RenderW, CSettings.RenderH); RectangleF rect; CHelper.SetRect(bounds, out rect, _VideoTexture.OrigAspect, EAspect.Crop); diff --git a/Vocaluxe/Lib/Draw/CDirect3D.cs b/Vocaluxe/Lib/Draw/CDirect3D.cs index d6c455b8..079fa61c 100644 --- a/Vocaluxe/Lib/Draw/CDirect3D.cs +++ b/Vocaluxe/Lib/Draw/CDirect3D.cs @@ -679,21 +679,21 @@ namespace Vocaluxe.Lib.Draw /// public CTexture CopyScreen() { - CTexture texture = new CTexture(-1, _W, _H) {W2 = _CheckForNextPowerOf2(_W), H2 = _CheckForNextPowerOf2(_H)}; + CTexture texture = _GetNewTexture(_W, _H); Surface backbufferSurface = _Device.GetBackBuffer(0, 0); - Texture tex = new Texture(_Device, _W, _H, 0, Usage.AutoGenerateMipMap, Format.A8R8G8B8, Pool.Managed); + Texture tex = new Texture(_Device, texture.W2, texture.H2, 0, Usage.AutoGenerateMipMap, Format.A8R8G8B8, Pool.Managed); Surface textureSurface = tex.GetSurfaceLevel(0); Surface.FromSurface(textureSurface, backbufferSurface, Filter.Default, 0, new Rectangle(0, 0, _W, _H), new Rectangle(0, 0, _W, _H)); backbufferSurface.Dispose(); lock (_MutexTexture) { - _D3DTextures.Add(_IDs.Peek(), tex); texture.Index = _IDs.Dequeue(); + _D3DTextures.Add(texture.Index, tex); _Textures[texture.Index] = texture; + return texture; } - return texture; } /// @@ -856,16 +856,11 @@ namespace Vocaluxe.Lib.Draw break; } - CTexture texture = new CTexture(-1, bmp.Width, bmp.Height) {UseFullTexture = true}; - int w = Math.Min(bmp.Width, maxSize); int h = Math.Min(bmp.Height, maxSize); w = _CheckForNextPowerOf2(w); h = _CheckForNextPowerOf2(h); - texture.W2 = w; - texture.H2 = h; - Bitmap bmp2 = null; byte[] data; try @@ -896,12 +891,13 @@ namespace Vocaluxe.Lib.Draw bmp2.Dispose(); } + CTexture texture = new CTexture(bmp.Width, bmp.Height, w, h,true); return _AddTexture(texture, w, data); } public CTexture AddTexture(int w, int h, byte[] data) { - CTexture texture = new CTexture(-1, w, h) {W2 = _CheckForNextPowerOf2(w), H2 = _CheckForNextPowerOf2(h)}; + CTexture texture = _GetNewTexture(w, h); return _AddTexture(texture, w, data); } @@ -936,8 +932,6 @@ namespace Vocaluxe.Lib.Draw rect.Data.Position += rect.Pitch; } t.UnlockRectangle(0); - - texture.TexturePath = String.Empty; } catch (Exception) { @@ -950,7 +944,7 @@ namespace Vocaluxe.Lib.Draw public CTexture EnqueueTexture(int w, int h, byte[] data) { - CTexture texture = new CTexture(-1, w, h); + CTexture texture = _GetNewTexture(w, h); STextureQueue queue = new STextureQueue {Data = data, Height = h, Width = w}; lock (_MutexTexture) @@ -963,6 +957,11 @@ namespace Vocaluxe.Lib.Draw } return texture; } + + private CTexture _GetNewTexture(int w, int h) + { + return new CTexture(w, h, _CheckForNextPowerOf2(w), _CheckForNextPowerOf2(h)); + } #endregion adding #region updating diff --git a/Vocaluxe/Lib/Draw/CDrawWinForm.cs b/Vocaluxe/Lib/Draw/CDrawWinForm.cs index b13a52c6..ca19a4fa 100644 --- a/Vocaluxe/Lib/Draw/CDrawWinForm.cs +++ b/Vocaluxe/Lib/Draw/CDrawWinForm.cs @@ -291,7 +291,7 @@ namespace Vocaluxe.Lib.Draw { Bitmap bmp = new Bitmap(_Backbuffer); _Bitmaps.Add(bmp); - CTexture texture = new CTexture(_Bitmaps.Count - 1, bmp.Width, bmp.Height); + CTexture texture = _GetNewTexture(bmp.Width, bmp.Height); // Add to Texture List _Textures[texture.Index] = texture; @@ -335,7 +335,7 @@ namespace Vocaluxe.Lib.Draw { Bitmap bmp2 = new Bitmap(bmp); _Bitmaps.Add(bmp2); - CTexture texture = new CTexture(_Bitmaps.Count - 1, bmp.Width, bmp.Height); + CTexture texture = _GetNewTexture(bmp.Width, bmp.Height); // Add to Texture List _Textures[texture.Index] = texture; @@ -343,6 +343,11 @@ namespace Vocaluxe.Lib.Draw return texture; } + private CTexture _GetNewTexture(int w, int h) + { + return new CTexture(w, h) {Index = _Bitmaps.Count - 1}; + } + public CTexture AddTexture(string texturePath) { if (File.Exists(texturePath)) diff --git a/Vocaluxe/Lib/Draw/COpenGL.cs b/Vocaluxe/Lib/Draw/COpenGL.cs index c404b037..8dd43f54 100644 --- a/Vocaluxe/Lib/Draw/COpenGL.cs +++ b/Vocaluxe/Lib/Draw/COpenGL.cs @@ -491,14 +491,11 @@ namespace Vocaluxe.Lib.Draw public CTexture CopyScreen() { - CTexture texture = new CTexture(-1, _W, _H); + CTexture texture = _GetNewTexture(_W, _H); + int id = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, id); texture.ID = id; - - texture.W2 = MathHelper.NextPowerOfTwo(texture.OrigSize.Width); - texture.H2 = MathHelper.NextPowerOfTwo(texture.OrigSize.Height); - 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, _X, _Y, _W, _H); @@ -699,20 +696,16 @@ namespace Vocaluxe.Lib.Draw break; } - CTexture texture = new CTexture(-1, bmp.Width, bmp.Height) {UseFullTexture = true}; - - int id = GL.GenTexture(); - GL.BindTexture(TextureTarget.Texture2D, id); - texture.ID = id; - int w = Math.Min(bmp.Width, maxSize); int h = Math.Min(bmp.Height, maxSize); w = MathHelper.NextPowerOfTwo(w); h = MathHelper.NextPowerOfTwo(h); - texture.W2 = w; - texture.H2 = h; + CTexture texture = new CTexture(bmp.Width, bmp.Height, w, h, true); + int id = GL.GenTexture(); + GL.BindTexture(TextureTarget.Texture2D, id); + texture.ID = id; Bitmap bmp2 = null; try { @@ -764,9 +757,9 @@ namespace Vocaluxe.Lib.Draw public CTexture AddTexture(int w, int h, byte[] data) { - CTexture texture = new CTexture(-1, w, h); + CTexture texture = _GetNewTexture(w, h); - _CreateTexture(texture, data); + _CreateTexture(texture, w, h, data); lock (_MutexTexture) { @@ -777,10 +770,8 @@ namespace Vocaluxe.Lib.Draw return texture; } - private void _CreateTexture(CTexture texture, byte[] data) + private void _CreateTexture(CTexture texture, int w, int h, byte[] data) { - int w = texture.OrigSize.Width; - int h = texture.OrigSize.Height; if (_UsePBO) { try @@ -801,9 +792,6 @@ namespace Vocaluxe.Lib.Draw GL.BindTexture(TextureTarget.Texture2D, id); texture.ID = id; - texture.W2 = MathHelper.NextPowerOfTwo(w); - texture.H2 = MathHelper.NextPowerOfTwo(h); - 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, w, h, PixelFormat.Bgra, PixelType.UnsignedByte, data); @@ -818,14 +806,11 @@ namespace Vocaluxe.Lib.Draw //GL.GenerateMipmap(GenerateMipmapTarget.Texture2D); GL.Ext.GenerateMipmap(GenerateMipmapTarget.Texture2D); GL.BindTexture(TextureTarget.Texture2D, 0); - - // Add to Texture List - texture.TexturePath = String.Empty; } public CTexture EnqueueTexture(int w, int h, byte[] data) { - CTexture texture = new CTexture(-1, w, h); + CTexture texture = _GetNewTexture(w, h); STextureQueue queue = new STextureQueue {Data = data, Height = h, Width = w}; lock (_MutexTexture) @@ -838,6 +823,11 @@ namespace Vocaluxe.Lib.Draw return texture; } + + private CTexture _GetNewTexture(int w, int h) + { + return new CTexture(w, h, MathHelper.NextPowerOfTwo(w), MathHelper.NextPowerOfTwo(h)); + } #endregion adding #region updating @@ -1183,7 +1173,7 @@ namespace Vocaluxe.Lib.Draw continue; if (q.Width == texture.OrigSize.Width && q.Height == texture.OrigSize.Height) - _CreateTexture(texture, q.Data); + _CreateTexture(texture, q.Width, q.Height, q.Data); else CLog.LogError("Wrong texture size in queue!"); } diff --git a/Vocaluxe/Lib/Video/CVideoDecoder.cs b/Vocaluxe/Lib/Video/CVideoDecoder.cs index 691f5e96..79ea8b52 100644 --- a/Vocaluxe/Lib/Video/CVideoDecoder.cs +++ b/Vocaluxe/Lib/Video/CVideoDecoder.cs @@ -20,7 +20,6 @@ using System.Collections.Generic; using System.Linq; using VocaluxeLib.Draw; -using VocaluxeLib.Menu; namespace Vocaluxe.Lib.Video { diff --git a/Vocaluxe/Lib/Video/CVideoDecoderFFmpeg.cs b/Vocaluxe/Lib/Video/CVideoDecoderFFmpeg.cs index cef73875..fb5c2951 100644 --- a/Vocaluxe/Lib/Video/CVideoDecoderFFmpeg.cs +++ b/Vocaluxe/Lib/Video/CVideoDecoderFFmpeg.cs @@ -26,7 +26,6 @@ using System.Threading; using Vocaluxe.Base; using Vocaluxe.Lib.Video.Acinerella; using VocaluxeLib.Draw; -using VocaluxeLib.Menu; namespace Vocaluxe.Lib.Video { diff --git a/Vocaluxe/Lib/Video/CVideoDecoderGstreamer.cs b/Vocaluxe/Lib/Video/CVideoDecoderGstreamer.cs index 7bf76966..199b82d5 100644 --- a/Vocaluxe/Lib/Video/CVideoDecoderGstreamer.cs +++ b/Vocaluxe/Lib/Video/CVideoDecoderGstreamer.cs @@ -21,7 +21,6 @@ using System; using Vocaluxe.Base; using Vocaluxe.Lib.Video.Gstreamer; using VocaluxeLib.Draw; -using VocaluxeLib.Menu; namespace Vocaluxe.Lib.Video { diff --git a/Vocaluxe/Lib/Video/IVideoDecoder.cs b/Vocaluxe/Lib/Video/IVideoDecoder.cs index ef8d57c7..ded5d7a5 100644 --- a/Vocaluxe/Lib/Video/IVideoDecoder.cs +++ b/Vocaluxe/Lib/Video/IVideoDecoder.cs @@ -18,7 +18,6 @@ #endregion using VocaluxeLib.Draw; -using VocaluxeLib.Menu; namespace Vocaluxe.Lib.Video { diff --git a/Vocaluxe/Lib/Webcam/CAForgeNet.cs b/Vocaluxe/Lib/Webcam/CAForgeNet.cs index 5655707a..1413cd73 100644 --- a/Vocaluxe/Lib/Webcam/CAForgeNet.cs +++ b/Vocaluxe/Lib/Webcam/CAForgeNet.cs @@ -25,7 +25,6 @@ using System.Drawing.Imaging; using System.Runtime.InteropServices; using Vocaluxe.Base; using VocaluxeLib.Draw; -using VocaluxeLib.Menu; namespace Vocaluxe.Lib.Webcam { diff --git a/Vocaluxe/Lib/Webcam/IWebcam.cs b/Vocaluxe/Lib/Webcam/IWebcam.cs index 0d8042ef..3244c218 100644 --- a/Vocaluxe/Lib/Webcam/IWebcam.cs +++ b/Vocaluxe/Lib/Webcam/IWebcam.cs @@ -20,7 +20,6 @@ using System.Collections.Generic; using System.Drawing; using VocaluxeLib.Draw; -using VocaluxeLib.Menu; namespace Vocaluxe.Lib.Webcam { diff --git a/Vocaluxe/Screens/CScreenScore.cs b/Vocaluxe/Screens/CScreenScore.cs index b1869a6c..b50723ee 100644 --- a/Vocaluxe/Screens/CScreenScore.cs +++ b/Vocaluxe/Screens/CScreenScore.cs @@ -22,7 +22,6 @@ using System.Collections.Generic; using System.Diagnostics; using System.Windows.Forms; using Vocaluxe.Base; -using VocaluxeLib.Draw; using VocaluxeLib.Menu; using VocaluxeLib.Menu.SongMenu; diff --git a/VocaluxeLib/Draw/CTexture.cs b/VocaluxeLib/Draw/CTexture.cs index c0604f3e..f3823112 100644 --- a/VocaluxeLib/Draw/CTexture.cs +++ b/VocaluxeLib/Draw/CTexture.cs @@ -65,6 +65,7 @@ namespace VocaluxeLib.Draw /// public float HeightRatio { get; private set; } + /* /// /// Internal use. Specifies if full texture memory should be used /// Set to true if you resized the original image to the maximum @@ -87,16 +88,25 @@ namespace VocaluxeLib.Draw } } } +*/ - public CTexture(int index, int origWidth = 1, int origHeight = 1) + /// + /// Creates a new texture reference + /// + /// Original width (Bitmap size) + /// Original height (Bitmap size) + /// Width in video memory + /// Height in video memory + /// True if it is using the full size of the video memory (no blank parts due to Pow-2-Issue) + public CTexture(int origWidth, int origHeight, int texWidth = 0, int texHeight = 0, bool useFullTexture = false) { - Index = index; - OrigSize = new Size(origWidth, origHeight); Rect = new SRectF(0f, 0f, origWidth, origHeight, 0f); + _UseFullTexture = useFullTexture; - _W2 = origWidth; - _H2 = origHeight; + //IMPORTANT: Use setter here to calculate ratios! + W2 = (texWidth > 0) ? texWidth : origWidth; + H2 = (texHeight > 0) ? texHeight : origHeight; } } } \ No newline at end of file