From: jpbruyere Date: Wed, 20 Jan 2016 06:41:44 +0000 (+0100) Subject: cairogl first test, not working X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=d15711aef9c489baec328fb45c76cd4e29dd17b9;p=jp%2Fcrow.git cairogl first test, not working --- diff --git a/GOLib.csproj b/GOLib.csproj index 647e8782..0e3668d0 100644 --- a/GOLib.csproj +++ b/GOLib.csproj @@ -46,7 +46,7 @@ bin\Debug - TRACE;DEBUG;__linux__;DEBUG_LOAD_TIME0;DEBUG_LAYOUTING;DEBUG_BINDING + TRACE;DEBUG;__linux__;CAIRO_GL;DEBUG_LOAD_TIME0;DEBUG_LAYOUTING0;DEBUG_BINDING0 - + \ No newline at end of file diff --git a/Tests/GOLIBTests.cs b/Tests/GOLIBTests.cs index 36bec18d..a3e8b1fa 100644 --- a/Tests/GOLIBTests.cs +++ b/Tests/GOLIBTests.cs @@ -28,7 +28,7 @@ namespace test #endregion public GOLIBTests () - : base(800, 600,"test: press spacebar to toogle test files") + : base(1280, 1024,"test: press spacebar to toogle test files") { VSync = VSyncMode.Off; } @@ -36,6 +36,8 @@ namespace test int frameCpt = 0; int idx = 0; string[] testFiles = { + "test0.goml", +// "test4.goml", // "testCombobox.goml", "testWindow3.goml", "testExpandable.goml", @@ -47,7 +49,6 @@ namespace test "testWindow.goml", "testWindow2.goml", // "testSpinner.goml", - "test4.goml", "testRadioButton2.goml", "testContainer.goml", "testBorder.goml", diff --git a/Tests/Interfaces/test0.goml b/Tests/Interfaces/test0.goml index e7c8425a..f0b78d14 100755 --- a/Tests/Interfaces/test0.goml +++ b/Tests/Interfaces/test0.goml @@ -1,12 +1,2 @@  - - - - - - - - + diff --git a/Tests/Interfaces/test4.goml b/Tests/Interfaces/test4.goml index 6bd2e14c..e4fff74f 100755 --- a/Tests/Interfaces/test4.goml +++ b/Tests/Interfaces/test4.goml @@ -44,7 +44,7 @@ BorderColor="DimGray" BorderWidth="1" Text="editable text"/> - + @@ -73,25 +73,25 @@ - + - + - - - + + + - + diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 14c98c01..e6f7fda6 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -38,10 +38,10 @@ + - ..\..\opentk\Binaries\OpenTK\Release\OpenTK.dll + ..\..\..\src\opentk-git\Binaries\OpenTK\Release\OpenTK.dll - diff --git a/src/GraphicObjects/GenericStack.cs b/src/GraphicObjects/GenericStack.cs index b5af394d..5f525905 100644 --- a/src/GraphicObjects/GenericStack.cs +++ b/src/GraphicObjects/GenericStack.cs @@ -127,7 +127,7 @@ namespace go if (idx > 0 && idx < Children.Count - 1) gobjs [0].Slot.Width -= Spacing; if (gobjs [0].LastSlots.Width != gobjs [0].Slot.Width) { - gobjs [0].bmp = null; + gobjs [0].DeleteCache(); gobjs [0].OnLayoutChanges (LayoutingType.Width); gobjs [0].LastSlots.Width = gobjs [0].Slot.Width; } @@ -147,7 +147,7 @@ namespace go if (idx > 0 && idx < Children.Count - 1) gobjs [0].Slot.Height -= Spacing; if (gobjs [0].LastSlots.Height != gobjs [0].Slot.Height) { - gobjs [0].bmp = null; + gobjs [0].DeleteCache(); gobjs [0].OnLayoutChanges (LayoutingType.Height); gobjs [0].LastSlots.Height = gobjs [0].Slot.Height; } @@ -157,7 +157,7 @@ namespace go } ComputeChildrenPositions (); //if no layouting remains in queue for item, registre for redraw - if (Interface.LayoutingQueue.Where (lq => lq.GraphicObject == this).Count () <= 0 && bmp==null) + if (Interface.LayoutingQueue.Where (lq => lq.GraphicObject == this).Count () <= 0 && cacheIsEmpty) this.RegisterForRedraw (); }else base.UpdateLayout(layoutType); diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index fe707957..e54f4b12 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -2,8 +2,9 @@ using System.Collections.Generic; using System.Linq; using System.Text; - -//using OpenTK.Graphics.OpenGL; +#if CAIRO_GL +using OpenTK.Graphics.OpenGL; +#endif using System.Drawing.Imaging; using System.Diagnostics; using OpenTK.Input; @@ -89,7 +90,12 @@ namespace go public Rectangle Bounds; public Rectangle Slot = new Rectangle (); public object Tag; + #if CAIRO_GL + public static Cairo.Device device; + public uint texID; + #else public byte[] bmp; + #endif #endregion #region ILayoutable @@ -317,9 +323,25 @@ namespace go } //TODO: only used in group, should be removed from base go object [XmlIgnore]public virtual bool DrawingIsValid - { get { return bmp == null ? - false : - true; } } + { + get { + #if CAIRO_GL + return GL.IsTexture(texID); + #else + return bmp != null; + #endif + } + } + [XmlIgnore]protected bool cacheIsEmpty + { + get { + #if CAIRO_GL + return !GL.IsTexture(texID); + #else + return bmp == null; + #endif + } + } [XmlAttributeAttribute()][DefaultValue(null)] public virtual string BackgroundImagePath { get { return _backgroundImagePath; } @@ -449,7 +471,7 @@ namespace go /// public virtual void registerForGraphicUpdate () { - bmp = null; + DeleteCache (); if (TopContainer != null) TopContainer.gobjsToRedraw.Add (this); } @@ -604,7 +626,7 @@ namespace go if (LastSlots.X == Slot.X) break; - bmp = null; + DeleteCache (); OnLayoutChanges (layoutType); @@ -623,13 +645,13 @@ namespace go Slot.Y = Parent.ClientRectangle.Height / 2 - Slot.Height / 2; break; } - }else + } else Slot.Y = Bounds.Y; if (LastSlots.Y == Slot.Y) break; - bmp = null; + DeleteCache (); OnLayoutChanges (layoutType); @@ -657,7 +679,7 @@ namespace go if (LastSlots.Width == Slot.Width) break; - bmp = null; + DeleteCache (); OnLayoutChanges (layoutType); @@ -685,7 +707,7 @@ namespace go if (LastSlots.Height == Slot.Height) break; - bmp = null; + DeleteCache (); OnLayoutChanges (layoutType); @@ -694,7 +716,7 @@ namespace go } lock (Interface.LayoutingQueue) { //if no layouting remains in queue for item, registre for redraw - if (Interface.LayoutingQueue.Where (lq => lq.GraphicObject == this).Count () <= 0 && bmp == null) + if (Interface.LayoutingQueue.Where (lq => lq.GraphicObject == this).Count () <= 0 && cacheIsEmpty) this.RegisterForRedraw (); } } @@ -721,13 +743,25 @@ namespace go { LastPaintedSlot = Slot; + #if CAIRO_GL + DeleteCache (); + GL.GenTextures(1, out texID); + GL.BindTexture(TextureTarget.Texture2D, texID); + GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, + Slot.Width, Slot.Height, 0, + OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero); + using (Surface draw = new GLSurface + (device, Content.ColorAlpha, texID, Slot.Width, Slot.Height)) { + #else + bmp = null; int stride = 4 * Slot.Width; int bmpSize = Math.Abs (stride) * Slot.Height; bmp = new byte[bmpSize]; - using (ImageSurface draw = - new ImageSurface(bmp, Format.Argb32, Slot.Width, Slot.Height, stride)) { + using (Surface draw = + new ImageSurface(bmp, Format.Argb32, Slot.Width, Slot.Height, stride)) { + #endif using (Context gr = new Context (draw)) { gr.Antialias = Antialias.Subpixel; onDraw (gr); @@ -735,6 +769,9 @@ namespace go draw.Flush (); //draw.WriteToPng ("/mnt/data/test.png"); } + #if CAIRO_GL + GL.BindTexture(TextureTarget.Texture2D, 0); + #endif } /// Chained painting routine on the parent context of the actual cached version /// of the widget @@ -743,12 +780,18 @@ namespace go if (!Visible) return; - if (bmp == null) + if (cacheIsEmpty) UpdateGraphic (); Rectangle rb = Parent.ContextCoordinates(Slot); - using (ImageSurface source = new ImageSurface(bmp, Format.Argb32, rb.Width, rb.Height, 4 * Slot.Width)) { + #if CAIRO_GL + using (Surface source = new GLSurface + (device, Content.ColorAlpha, texID, rb.Width, rb.Height)) { + #else + using (Surface source = + new ImageSurface(bmp, Format.Argb32, rb.Width, rb.Height, 4 * Slot.Width)) { + #endif if (this.Background == Color.Clear) { ctx.Save (); ctx.Operator = Operator.Clear; @@ -761,6 +804,16 @@ namespace go } } + public void DeleteCache() + { + #if CAIRO_GL + if (GL.IsTexture(texID)) + GL.DeleteTexture(texID); + #else + bmp = null; + #endif + } + #region Keyboard handling public virtual void onKeyDown(object sender, KeyboardKeyEventArgs e){ KeyDown.Raise (sender, e); diff --git a/src/GraphicObjects/Grid.cs b/src/GraphicObjects/Grid.cs index e8bd7ba6..8275299b 100644 --- a/src/GraphicObjects/Grid.cs +++ b/src/GraphicObjects/Grid.cs @@ -137,7 +137,7 @@ namespace go if (layoutType == LayoutingType.PositionChildren) { ComputeChildrenPositions (); //if no layouting remains in queue for item, registre for redraw - if (Interface.LayoutingQueue.Where (lq => lq.GraphicObject == this).Count () <= 0 && bmp==null) + if (Interface.LayoutingQueue.Where (lq => lq.GraphicObject == this).Count () <= 0 && cacheIsEmpty) this.RegisterForRedraw (); }else base.UpdateLayout(layoutType); diff --git a/src/GraphicObjects/Group.cs b/src/GraphicObjects/Group.cs index 89afa5f2..b363342d 100644 --- a/src/GraphicObjects/Group.cs +++ b/src/GraphicObjects/Group.cs @@ -204,7 +204,7 @@ namespace go if ( !Visible ) return; - if (bmp == null) + if (cacheIsEmpty) UpdateGraphic (); else { @@ -223,9 +223,13 @@ namespace go if (!DrawingIsValid || clip != null) {//false when 1 child has changed //child having their content changed has to be repainted //and those with slot intersecting clip rectangle have also to be repainted - - using (ImageSurface cache = - new ImageSurface (bmp, Format.Argb32, Slot.Width, Slot.Height, Slot.Width * 4)) { + #if CAIRO_GL + using (Surface cache = new GLSurface + (device, Content.ColorAlpha, texID, Slot.Width, Slot.Height)) { + #else + using (Surface cache = + new ImageSurface(bmp, Format.Argb32, Slot.Width, Slot.Height, 4 * Slot.Width)) { + #endif Context gr = new Context (cache); clip.clearAndClip (gr); diff --git a/src/OpenGL/TexturedShader.cs b/src/OpenGL/TexturedShader.cs index e62613d1..af3d25c2 100644 --- a/src/OpenGL/TexturedShader.cs +++ b/src/OpenGL/TexturedShader.cs @@ -7,7 +7,27 @@ namespace go.GLBackend { public TexturedShader () { + vertSource = @" + #version 130 + + precision highp float; + + uniform mat4 Projection; + uniform mat4 ModelView; + uniform mat4 Model; + uniform mat4 Normal; + + in vec2 in_position; + in vec2 in_tex; + out vec2 texCoord; + + + void main(void) + { + texCoord = in_tex; + gl_Position = Projection * ModelView * Model * vec4(in_position, 0, 1); + }"; fragSource = @" #version 130 precision highp float; diff --git a/src/OpenTKGameWindow.cs b/src/OpenTKGameWindow.cs index 5fbcd9c1..ebe0c2df 100755 --- a/src/OpenTKGameWindow.cs +++ b/src/OpenTKGameWindow.cs @@ -27,7 +27,7 @@ namespace go public OpenTKGameWindow(int _width, int _height, string _title="golib") : base(_width, _height, new OpenTK.Graphics.GraphicsMode(32, 24, 0, 1), _title,GameWindowFlags.Default,DisplayDevice.GetDisplay(DisplayIndex.Second), - 3,3,OpenTK.Graphics.GraphicsContextFlags.Debug) + 3,3,OpenTK.Graphics.GraphicsContextFlags.Default) // public OpenTKGameWindow(int _width, int _height, string _title="golib") // : base(_width, _height, new OpenTK.Graphics.GraphicsMode(32, 24, 0, 8), _title) { @@ -158,8 +158,14 @@ namespace go #region graphic contexte Context ctx; Surface surf; + #if CAIRO_GL + public Device device; + OpenTK.Graphics.IGraphicsContext cairoGLContext; + #else byte[] bmp; - int texID; + #endif + + uint texID; public QuadVAO uiQuad, uiQuad2; go.GLBackend.Shader shader; @@ -167,9 +173,17 @@ namespace go Rectangle dirtyZone = Rectangle.Empty; void createContext() - { + { + #if CAIRO_GL + cairoGLContext.MakeCurrent(this.WindowInfo); + #endif + createOpenGLSurface (); + #if CAIRO_GL + this.MakeCurrent(); + #endif + if (uiQuad != null) uiQuad.Dispose (); uiQuad = new QuadVAO (0, 0, ClientRectangle.Width, ClientRectangle.Height, 0, 1, 1, -1); @@ -179,15 +193,13 @@ namespace go (0, ClientRectangle.Width, ClientRectangle.Height, 0, 0, 1); redrawClip.AddRectangle (ClientRectangle); + + } void createOpenGLSurface() { currentWindow = this; - int stride = 4 * ClientRectangle.Width; - int bmpSize = Math.Abs (stride) * ClientRectangle.Height; - bmp = new byte[bmpSize]; - //create texture if (GL.IsTexture(texID)) GL.DeleteTexture (texID); @@ -195,16 +207,29 @@ namespace go GL.ActiveTexture (TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, texID); + #if CAIRO_GL + if (surf != null) + surf.Dispose(); + GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, + ClientRectangle.Width, ClientRectangle.Height, 0, + OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero); + surf = new Cairo.GLSurface (device, Cairo.Content.ColorAlpha, texID, + ClientRectangle.Width, ClientRectangle.Height); + #else + int stride = 4 * ClientRectangle.Width; + int bmpSize = Math.Abs (stride) * ClientRectangle.Height; + bmp = new byte[bmpSize]; + GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, ClientRectangle.Width, ClientRectangle.Height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bmp); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); - + #endif GL.BindTexture(TextureTarget.Texture2D, 0); - shader.Texture = texID; + shader.Texture = (int)texID; } void OpenGLDraw() { @@ -213,10 +238,12 @@ namespace go shader.Enable (); + #if CAIRO_GL + #else GL.TexSubImage2D (TextureTarget.Texture2D, 0, 0, 0, ClientRectangle.Width, ClientRectangle.Height, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bmp); - + #endif uiQuad.Render (PrimitiveType.TriangleStrip); GL.BindTexture(TextureTarget.Texture2D, 0); @@ -224,23 +251,7 @@ namespace go shader.Disable (); GL.Viewport (viewport [0], viewport [1], viewport [2], viewport [3]); } -// public void RenderCustomTextureOnUIQuad(int _customTex) -// { -// GL.GetInteger (GetPName.Viewport, viewport); -// GL.Viewport (0, 0, ClientRectangle.Width, ClientRectangle.Height); -// -// shader.Enable (); -// -// GL.ActiveTexture (TextureUnit.Texture0); -// GL.BindTexture (TextureTarget.Texture2D, _customTex); -// GL.Disable (EnableCap.DepthTest); -// uiQuad2.Render (PrimitiveType.TriangleStrip); -// GL.Enable (EnableCap.DepthTest); -// GL.BindTexture(TextureTarget.Texture2D, 0); -// shader.Disable (); -// GL.Viewport (viewport [0], viewport [1], viewport [2], viewport [3]); -// } - + #endregion #region update @@ -256,7 +267,13 @@ namespace go guTime.Reset (); drawingTime.Reset (); + #if CAIRO_GL + GraphicObject.device = device; + cairoGLContext.MakeCurrent(this.WindowInfo); + #else surf = new ImageSurface(bmp, Format.Argb32, ClientRectangle.Width, ClientRectangle.Height,ClientRectangle.Width*4); + #endif + ctx = new Context(surf); if (Interface.LoadingLists.Count > 0) { @@ -329,9 +346,17 @@ namespace go redrawClip.Reset (); } } + surf.Flush (); //surf.WriteToPng (@"/mnt/data/test.png"); ctx.Dispose (); + #if CAIRO_GL + this.MakeCurrent (); + #else surf.Dispose (); + #endif + + + // if (ToolTip.isVisible) { // ToolTip.panel.processkLayouting(); // if (ToolTip.panel.layoutIsValid) @@ -379,7 +404,6 @@ namespace go { GLClear (); - base.OnRenderFrame(e); OnRender (e); @@ -410,6 +434,14 @@ namespace go int mts = GL.GetInteger (GetPName.MaxTextureSize); shader = new go.GLBackend.TexturedShader (); + + #if CAIRO_GL + cairoGLContext = OpenTK.Platform.Utilities.CloneGLContext (this); + IntPtr dpy = OpenTK.Platform.Utilities.GetDisplay(this.WindowInfo); + cairoGLContext.MakeCurrent(this.WindowInfo); + device = new Cairo.Device (dpy, + (cairoGLContext as OpenTK.Graphics.IGraphicsContextInternal).Context.Handle); + #endif } protected override void OnResize(EventArgs e)