]> O.S.I.I.S - jp/crow.git/commitdiff
cairogl first test, not working
authorjpbruyere <jp.bruyere@hotmail.com>
Wed, 20 Jan 2016 06:41:44 +0000 (07:41 +0100)
committerjpbruyere <jp.bruyere@hotmail.com>
Wed, 20 Jan 2016 06:41:44 +0000 (07:41 +0100)
15 files changed:
GOLib.csproj
GOLib.sln
MonoDevelop.GOLib/MonoDevelop.GOLib.csproj
Templates/ComboboxOverlay.goml
Tests/GOLIBTests.cs
Tests/Interfaces/test0.goml
Tests/Interfaces/test4.goml
Tests/Interfaces/testWindow.goml
Tests/Tests.csproj
src/GraphicObjects/GenericStack.cs
src/GraphicObjects/GraphicObject.cs
src/GraphicObjects/Grid.cs
src/GraphicObjects/Group.cs
src/OpenGL/TexturedShader.cs
src/OpenTKGameWindow.cs

index 647e8782e7a0d014b9cfcee7342c047c4fdb9e9d..0e3668d0f600ee09daa87956fd23cfed2f5ed352 100644 (file)
@@ -46,7 +46,7 @@
   </PropertyGroup>\r
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">\r
     <OutputPath>bin\Debug</OutputPath>\r
-    <DefineConstants>TRACE;DEBUG;__linux__;DEBUG_LOAD_TIME0;DEBUG_LAYOUTING;DEBUG_BINDING</DefineConstants>\r
+    <DefineConstants>TRACE;DEBUG;__linux__;CAIRO_GL;DEBUG_LOAD_TIME0;DEBUG_LAYOUTING0;DEBUG_BINDING0</DefineConstants>\r
   </PropertyGroup>\r
   <!--  <PropertyGroup Condition=" '$(Platform)' == 'Linux_x86' ">\r
     <DefineConstants>__linux__</DefineConstants>\r
       <Package>glib-sharp-3.0</Package>\r
     </Reference>\r
     <Reference Include="Microsoft.CSharp" />\r
-    <Reference Include="OpenTK">\r
-      <HintPath>..\opentk\Binaries\OpenTK\Release\OpenTK.dll</HintPath>\r
-    </Reference>\r
     <Reference Include="Mono.Cairo" />\r
-    <Reference Include="rsvg2-sharp, Version=2.18.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f">\r
-      <Package>rsvg2-sharp-2.0</Package>\r
+    <Reference Include="rsvg2-sharp, Version=2.18.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />\r
+    <Reference Include="OpenTK">\r
+      <HintPath>..\..\src\opentk-git\Binaries\OpenTK\Release\OpenTK.dll</HintPath>\r
     </Reference>\r
   </ItemGroup>\r
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />\r
     <None Include="Images\Icons\Cursors\move" />\r
     <None Include="README.md" />\r
   </ItemGroup>\r
+  <ProjectExtensions>\r
+    <MonoDevelop>\r
+      <Properties>\r
+        <Policies>\r
+          <TextStylePolicy FileWidth="120" TabsToSpaces="False" EolMarker="Unix" inheritsSet="VisualStudio" inheritsScope="text/plain" scope="text/x-csharp" />\r
+          <CSharpFormattingPolicy AfterDelegateDeclarationParameterComma="True" inheritsSet="Mono" inheritsScope="text/x-csharp" scope="text/x-csharp" />\r
+        </Policies>\r
+      </Properties>\r
+    </MonoDevelop>\r
+  </ProjectExtensions>\r
 </Project>\r
index 03d54156c94ae45ae34be7d7e09ee8b41a10091f..6d62bc2a0d103c52980205745dd18059ca2780f5 100644 (file)
--- a/GOLib.sln
+++ b/GOLib.sln
@@ -26,10 +26,10 @@ Global
                {C2980F9B-4798-4C05-99E2-E174810F7C7B}.Release|Linux_x86.ActiveCfg = Release|Any CPU\r
                {C2980F9B-4798-4C05-99E2-E174810F7C7B}.Release|Linux_x86.Build.0 = Release|Any CPU\r
                {E9E14DB5-3C67-4E01-B5C3-4D90D7E31A2E}.Debug|Linux_x86.ActiveCfg = Debug|Any CPU\r
-               {E9E14DB5-3C67-4E01-B5C3-4D90D7E31A2E}.Debug|Linux_x86.Build.0 = Debug|Any CPU\r
                {E9E14DB5-3C67-4E01-B5C3-4D90D7E31A2E}.Release|Linux_x86.ActiveCfg = Release|Any CPU\r
        EndGlobalSection\r
        GlobalSection(MonoDevelopProperties) = preSolution\r
+               StartupItem = Tests\Tests.csproj\r
                Policies = $0\r
                $0.StandardHeader = $1\r
                $1.Text = @ \n ${FileName}\n \n Author:\n      ${AuthorName} <${AuthorEmail}>\n\n Copyright (c) ${Year} ${CopyrightHolder}\n\n This program is free software: you can redistribute it and/or modify\n it under the terms of the GNU General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n This program is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n GNU General Public License for more details.\n\n You should have received a copy of the GNU General Public License\n along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
index b2099b5a651138fc36514b56f5b9737ab5e97280..416beea0d47732d71a0644600c7f5284b5a46cf4 100644 (file)
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
     <ConsolePause>false</ConsolePause>
+    <CustomCommands>
+      <CustomCommands>
+        <Command type="Execute" command="/usr/local/lib/monodevelop/bin/MonoDevelop.exe --no-redirect" workingdir="/usr/local/lib/monodevelop/bin" />
+      </CustomCommands>
+    </CustomCommands>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
     <DebugType>none</DebugType>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
     <ConsolePause>false</ConsolePause>
+    <CustomCommands>
+      <CustomCommands>
+        <Command type="Execute" command="/usr/local/lib/monodevelop/bin/MonoDevelop.exe --no-redirect" workingdir="/usr/local/lib/monodevelop/bin" />
+      </CustomCommands>
+    </CustomCommands>
   </PropertyGroup>
   <ItemGroup>
     <Reference Include="System" />
     <Reference Include="ICSharpCode.NRefactory">
       <HintPath>\usr\local\lib\monodevelop\bin\ICSharpCode.NRefactory.dll</HintPath>
-      <Private>False</Private>
-    </Reference>
-    <Reference Include="Mono.Addins">
-      <Package>mono-addins</Package>
+      <Package>monodevelop</Package>
     </Reference>
+    <Reference Include="Mono.Addins" />
     <Reference Include="MonoDevelop.Ide">
       <HintPath>\usr\local\lib\monodevelop\bin\MonoDevelop.Ide.dll</HintPath>
-      <Private>False</Private>
+      <Package>monodevelop</Package>
     </Reference>
     <Reference Include="MonoDevelop.Core">
       <HintPath>\usr\local\lib\monodevelop\bin\MonoDevelop.Core.dll</HintPath>
+      <Package>monodevelop</Package>
     </Reference>
     <Reference Include="MonoDevelop.DesignerSupport">
       <HintPath>\usr\local\lib\monodevelop\AddIns\MonoDevelop.DesignerSupport\MonoDevelop.DesignerSupport.dll</HintPath>
-      <Private>False</Private>
+      <Package>monodevelop-core-addins</Package>
     </Reference>
     <Reference Include="Mono.Cairo" />
     <Reference Include="gtk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f">
     </Reference>
     <Reference Include="MonoDevelop.SourceEditor2">
       <HintPath>..\..\..\..\..\usr\local\lib\monodevelop\AddIns\DisplayBindings\SourceEditor\MonoDevelop.SourceEditor2.dll</HintPath>
+      <Package>monodevelop-core-addins</Package>
     </Reference>
     <Reference Include="Mono.TextEditor">
       <HintPath>..\..\..\..\..\usr\local\lib\monodevelop\bin\Mono.TextEditor.dll</HintPath>
+      <Package>monodevelop</Package>
     </Reference>
   </ItemGroup>
   <ItemGroup>
index cab4953159e03dcb12e7a89a38c3e1cdcb73204b..ca9f3b3167bd5fd97ffe30afc087d808337cc6bf 100755 (executable)
@@ -1,7 +1,7 @@
 <?xml version="1.0"?>\r
-<Border BorderWidth="1" Margin="1" MinimumSize="20;20" Height="{../TemplatedHeight}" Width="{../TemplatedWidth}" >\r
+<Border BorderWidth="1" Margin="1" MinimumSize="100;100" MaximumSize="500;500" Fit="true" >\r
 <!--   <Scroller  Name="scroller1" Margin="1" VerticalScrolling="true"\r
                Height="{../../TemplatedHeight}" Width="{../../TemplatedWidth}">-->\r
-               <VerticalStack Height="-1" Width="{../../../TemplatedWidth}" Name="List" Margin="0" VerticalAlignment="Top"/>\r
+               <VerticalStack Fit="True" Name="List" Margin="0" VerticalAlignment="Top"/>\r
 <!--   </Scroller>-->\r
 </Border>
\ No newline at end of file
index 36bec18df742e8754792d4e591d6a9818b3b0e29..a3e8b1fa2b3a07d1facd6831f9dcd488d67afd5f 100644 (file)
@@ -28,7 +28,7 @@ namespace test
                #endregion\r
 \r
                public GOLIBTests ()\r
-                       : base(800, 600,"test: press spacebar to toogle test files")\r
+                       : base(1280, 1024,"test: press spacebar to toogle test files")\r
                {\r
                        VSync = VSyncMode.Off;\r
                }\r
@@ -36,6 +36,8 @@ namespace test
                int frameCpt = 0;\r
                int idx = 0;\r
                string[] testFiles = {\r
+                       "test0.goml",\r
+//                     "test4.goml",\r
 //                     "testCombobox.goml",\r
                        "testWindow3.goml",\r
                        "testExpandable.goml",\r
@@ -47,7 +49,6 @@ namespace test
                        "testWindow.goml",\r
                        "testWindow2.goml",\r
 //                     "testSpinner.goml",\r
-                       "test4.goml",\r
                        "testRadioButton2.goml",\r
                        "testContainer.goml",\r
                        "testBorder.goml",\r
index e7c8425a2060811ef0078adc6dcaf00a5b37907a..f0b78d144556c8ff7af21ef6902a49cac28660b5 100755 (executable)
@@ -1,12 +1,2 @@
 <?xml version="1.0"?>
-<Container Width="100" Height="100" Background="Red">
-       <Group>
-               <Border CornerRadius="5" BorderWidth="1" Margin="5"/>
-               <HorizontalStack  Fit="true" Background="Clear" 
-                       VerticalAlignment="Top" Left="10">
-                       <GraphicObject Width="3"/>
-                       <Label Text="GroupBox"/>
-                       <GraphicObject Width="5"/>
-               </HorizontalStack>
-       </Group>
-</Container>
+<GraphicObject Width="200" Background="Green"/>
index 6bd2e14c68da7f52ea403b2ceda5835a83d2d996..e4fff74f2b1a4cb9e481b4e3cb75c8a787a7fce1 100755 (executable)
@@ -44,7 +44,7 @@
                                                                BorderColor="DimGray" BorderWidth="1"\r
                                                                Text="editable text"/>\r
                        </VerticalStack>\r
-                       <VerticalStack Fit="true"  Margin="0" WidgetSpacing="1">\r
+                       <VerticalStack Width="200" Height="-1" Margin="0" WidgetSpacing="1" Background="Blue">\r
                                <Button  Margin="1" Width="150" Height="100">\r
                                        <Image Path="#Tests.image.tetra.png"/>\r
                                </Button>\r
                                                <Checkbox Name="chk2"/>\r
                                        </VerticalStack>                \r
                                </Expandable>\r
-                               <HorizontalStack>\r
+                               <HorizontalStack Fit="true">\r
                                        <Label Text="Update" FontColor="White"/>\r
                                        <Label Name="labUpdate" Text="{update}" FontSize="16" Width="60" TextAlignment="Center" Background="DarkGreen"/>\r
                                </HorizontalStack>\r
-                               <HorizontalStack>\r
+                               <HorizontalStack Fit="true">\r
                                        <Label Text="Fps:" Width = "30"/>\r
                                        <Label Name="labFps" Text="{fps}" Font="droid bold, 14"\r
                                                TextAlignment="Center" Background="AoEnglish"/>\r
                                </HorizontalStack>\r
-                               <HorizontalStack>\r
-                                       <Label Text="Min:" Width = "30"/>\r
-                                       <Label Name="labFpsMin" Text="{fpsMin}" Font="droid bold, 14"\r
-                                               TextAlignment="Center" Background="AoEnglish"/>\r
-                               </HorizontalStack>\r
-                               <HorizontalStack>\r
+                               <HorizontalStack  Fit="true">\r
                                        <Label Text="Max:" Width = "30"/>\r
                                        <Label Name="labFpsMax" Text="{fpsMax}" Font="droid bold, 14"\r
                                                TextAlignment="Center" Background="AoEnglish"/>\r
                                </HorizontalStack>\r
+                               <HorizontalStack Background="Red" Fit="true">\r
+                                       <Label Text="Min:" Width = "30"/>\r
+                                       <Label Name="labFpsMin" Text="{fpsMin}" Font="droid bold, 14"\r
+                                               TextAlignment="Center" Background="AoEnglish"/>\r
+                               </HorizontalStack>\r
                        </VerticalStack>\r
                        <HorizontalStack Width="-1">\r
                                <Scroller Name="scroller1" Background="DimGray" Width="-1"  \r
index c48f08e2227b693584273c5c82cbd70f1b9cbe7d..f2bc0a57b71853d75841d1a8e00f6170a68b5a1d 100755 (executable)
@@ -4,7 +4,7 @@
        <VerticalStack Name="contentVSStack" Margin="10" Spacing="10">\r
                <Slider Name="slider" Height="10" Width="0"/>\r
                <Groupbox Text="test"  Height="-1" Width="-1" Margin="5">\r
-                       <VerticalStack  Height="-1" Width="0" >\r
+                       <VerticalStack  Height="-1" Width="-1" >\r
                                <RadioButton  Caption="Radio 1" Background="Red" />\r
                                <RadioButton  Caption="Radio 2" IsChecked="true" />\r
                                <RadioButton  Caption="Radio 3" />\r
index 14c98c01af0c5f3cf803a578504457c9e4b37138..e6f7fda6a85fdd69e14e9854515b9856586744e5 100644 (file)
     <Reference Include="System.Data" />
     <Reference Include="System.Xml" />
     <Reference Include="System.Drawing" />
+    <Reference Include="Mono.Cairo" />
     <Reference Include="OpenTK">
-      <HintPath>..\..\opentk\Binaries\OpenTK\Release\OpenTK.dll</HintPath>
+      <HintPath>..\..\..\src\opentk-git\Binaries\OpenTK\Release\OpenTK.dll</HintPath>
     </Reference>
-    <Reference Include="Mono.Cairo" />
   </ItemGroup>
   <ItemGroup>
     <Compile Include="GOLIBTest_5.cs" />
index b5af394d6241d09c326fca7b4866d3fab4cd70e5..5f525905d0be88e91a73bb02b0c24e42b7b64e73 100644 (file)
@@ -127,7 +127,7 @@ namespace go
                                                                if (idx > 0 && idx < Children.Count - 1)\r
                                                                        gobjs [0].Slot.Width -= Spacing;\r
                                                                if (gobjs [0].LastSlots.Width != gobjs [0].Slot.Width) {\r
-                                                                       gobjs [0].bmp = null;\r
+                                                                       gobjs [0].DeleteCache();\r
                                                                        gobjs [0].OnLayoutChanges (LayoutingType.Width);\r
                                                                        gobjs [0].LastSlots.Width = gobjs [0].Slot.Width;\r
                                                                }\r
@@ -147,7 +147,7 @@ namespace go
                                                                if (idx > 0 && idx < Children.Count - 1)\r
                                                                        gobjs [0].Slot.Height -= Spacing;\r
                                                                if (gobjs [0].LastSlots.Height != gobjs [0].Slot.Height) {\r
-                                                                       gobjs [0].bmp = null;\r
+                                                                       gobjs [0].DeleteCache();\r
                                                                        gobjs [0].OnLayoutChanges (LayoutingType.Height);\r
                                                                        gobjs [0].LastSlots.Height = gobjs [0].Slot.Height;\r
                                                                }\r
@@ -157,7 +157,7 @@ namespace go
                                }                               \r
                                ComputeChildrenPositions ();\r
                                //if no layouting remains in queue for item, registre for redraw\r
-                               if (Interface.LayoutingQueue.Where (lq => lq.GraphicObject == this).Count () <= 0 && bmp==null)\r
+                               if (Interface.LayoutingQueue.Where (lq => lq.GraphicObject == this).Count () <= 0 && cacheIsEmpty)\r
                                        this.RegisterForRedraw ();\r
                        }else\r
                                base.UpdateLayout(layoutType);\r
index fe707957fce05fd6333127bc2a9ce733621fe2f4..e54f4b12816fe0284d5cf2a18d10e711bf661abf 100644 (file)
@@ -2,8 +2,9 @@
 using System.Collections.Generic;\r
 using System.Linq;\r
 using System.Text;\r
-\r
-//using OpenTK.Graphics.OpenGL;\r
+#if CAIRO_GL\r
+using OpenTK.Graphics.OpenGL;\r
+#endif\r
 using System.Drawing.Imaging;\r
 using System.Diagnostics;\r
 using OpenTK.Input;\r
@@ -89,7 +90,12 @@ namespace go
                public Rectangle Bounds;\r
                public Rectangle Slot = new Rectangle ();\r
                public object Tag;\r
+               #if CAIRO_GL\r
+               public static Cairo.Device device;\r
+               public uint texID;\r
+               #else\r
                public byte[] bmp;\r
+               #endif\r
                #endregion\r
 \r
                #region ILayoutable\r
@@ -317,9 +323,25 @@ namespace go
                }\r
                //TODO: only used in group, should be removed from base go object\r
                [XmlIgnore]public virtual bool DrawingIsValid\r
-               { get { return bmp == null ? \r
-                               false : \r
-                               true; } }\r
+               { \r
+                       get {\r
+                               #if CAIRO_GL\r
+                               return GL.IsTexture(texID);\r
+                               #else\r
+                               return bmp != null; \r
+                               #endif\r
+                       } \r
+               }\r
+               [XmlIgnore]protected bool cacheIsEmpty\r
+               { \r
+                       get {\r
+                               #if CAIRO_GL\r
+                               return !GL.IsTexture(texID);\r
+                               #else\r
+                               return bmp == null; \r
+                               #endif\r
+                       } \r
+               }\r
                [XmlAttributeAttribute()][DefaultValue(null)]\r
                public virtual string BackgroundImagePath {\r
                        get { return _backgroundImagePath; }\r
@@ -449,7 +471,7 @@ namespace go
                /// </summary>\r
                public virtual void registerForGraphicUpdate ()\r
                {\r
-                       bmp = null;\r
+                       DeleteCache ();\r
                        if (TopContainer != null)\r
                                TopContainer.gobjsToRedraw.Add (this);\r
                }\r
@@ -604,7 +626,7 @@ namespace go
                                if (LastSlots.X == Slot.X)\r
                                        break;\r
 \r
-                               bmp = null;\r
+                               DeleteCache ();\r
 \r
                                OnLayoutChanges (layoutType);\r
 \r
@@ -623,13 +645,13 @@ namespace go
                                                Slot.Y = Parent.ClientRectangle.Height / 2 - Slot.Height / 2;\r
                                                break;\r
                                        }\r
-                               }else\r
+                               } else\r
                                        Slot.Y = Bounds.Y;\r
 \r
                                if (LastSlots.Y == Slot.Y)\r
                                        break;\r
 \r
-                               bmp = null;\r
+                               DeleteCache ();\r
 \r
                                OnLayoutChanges (layoutType);\r
 \r
@@ -657,7 +679,7 @@ namespace go
                                if (LastSlots.Width == Slot.Width)\r
                                        break;\r
 \r
-                               bmp = null;\r
+                               DeleteCache ();\r
 \r
                                OnLayoutChanges (layoutType);\r
 \r
@@ -685,7 +707,7 @@ namespace go
                                if (LastSlots.Height == Slot.Height)\r
                                        break;\r
 \r
-                               bmp = null;\r
+                               DeleteCache ();\r
 \r
                                OnLayoutChanges (layoutType);\r
 \r
@@ -694,7 +716,7 @@ namespace go
                        }\r
                        lock (Interface.LayoutingQueue) {\r
                                //if no layouting remains in queue for item, registre for redraw\r
-                               if (Interface.LayoutingQueue.Where (lq => lq.GraphicObject == this).Count () <= 0 && bmp == null)\r
+                               if (Interface.LayoutingQueue.Where (lq => lq.GraphicObject == this).Count () <= 0 && cacheIsEmpty)\r
                                        this.RegisterForRedraw ();\r
                        }\r
                }\r
@@ -721,13 +743,25 @@ namespace go
                {\r
                        LastPaintedSlot = Slot;\r
 \r
+                       #if CAIRO_GL\r
+                       DeleteCache ();\r
+                       GL.GenTextures(1, out texID);\r
+                       GL.BindTexture(TextureTarget.Texture2D, texID);\r
+                       GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, \r
+                               Slot.Width, Slot.Height, 0,\r
+                               OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero);\r
+                       using (Surface draw = new GLSurface\r
+                               (device, Content.ColorAlpha, texID, Slot.Width, Slot.Height)) {\r
+                       #else\r
+                       bmp = null;\r
                        int stride = 4 * Slot.Width;\r
 \r
                        int bmpSize = Math.Abs (stride) * Slot.Height;\r
                        bmp = new byte[bmpSize];\r
 \r
-                       using (ImageSurface draw =\r
-                new ImageSurface(bmp, Format.Argb32, Slot.Width, Slot.Height, stride)) {\r
+                       using (Surface draw =\r
+                               new ImageSurface(bmp, Format.Argb32, Slot.Width, Slot.Height, stride)) {\r
+                       #endif\r
                                using (Context gr = new Context (draw)) {\r
                                        gr.Antialias = Antialias.Subpixel;\r
                                        onDraw (gr);\r
@@ -735,6 +769,9 @@ namespace go
                                draw.Flush ();\r
                                //draw.WriteToPng ("/mnt/data/test.png");\r
                        }\r
+                       #if CAIRO_GL\r
+                       GL.BindTexture(TextureTarget.Texture2D, 0);\r
+                       #endif\r
                }\r
                /// <summary> Chained painting routine on the parent context of the actual cached version\r
                /// of the widget </summary>\r
@@ -743,12 +780,18 @@ namespace go
                        if (!Visible)\r
                                return;\r
 \r
-                       if (bmp == null)\r
+                       if (cacheIsEmpty)\r
                                UpdateGraphic ();\r
 \r
                        Rectangle rb = Parent.ContextCoordinates(Slot);\r
 \r
-                       using (ImageSurface source = new ImageSurface(bmp, Format.Argb32, rb.Width, rb.Height, 4 * Slot.Width)) {\r
+                       #if CAIRO_GL\r
+                       using (Surface source = new GLSurface\r
+                               (device, Content.ColorAlpha, texID, rb.Width, rb.Height)) {\r
+                       #else\r
+                       using (Surface source =\r
+                       new ImageSurface(bmp, Format.Argb32, rb.Width, rb.Height, 4 * Slot.Width)) {\r
+                       #endif\r
                                if (this.Background == Color.Clear) {\r
                                        ctx.Save ();\r
                                        ctx.Operator = Operator.Clear;\r
@@ -761,6 +804,16 @@ namespace go
                        }\r
                }\r
 \r
+               public void DeleteCache()\r
+               {\r
+                       #if CAIRO_GL\r
+                       if (GL.IsTexture(texID))\r
+                               GL.DeleteTexture(texID);\r
+                       #else\r
+                       bmp = null;\r
+                       #endif                  \r
+               }\r
+\r
         #region Keyboard handling\r
                public virtual void onKeyDown(object sender, KeyboardKeyEventArgs e){\r
                        KeyDown.Raise (sender, e);\r
index e8bd7ba6333c09588409a3d094f8ab056dd49b96..8275299b6b16a61cfed6db5994c1728c1d22f7bd 100644 (file)
@@ -137,7 +137,7 @@ namespace go
                        if (layoutType == LayoutingType.PositionChildren) {                             \r
                                ComputeChildrenPositions ();\r
                                //if no layouting remains in queue for item, registre for redraw\r
-                               if (Interface.LayoutingQueue.Where (lq => lq.GraphicObject == this).Count () <= 0 && bmp==null)\r
+                               if (Interface.LayoutingQueue.Where (lq => lq.GraphicObject == this).Count () <= 0 && cacheIsEmpty)\r
                                        this.RegisterForRedraw ();\r
                        }else\r
                                base.UpdateLayout(layoutType);\r
index 89afa5f242dd78087463732e0240a4fc89908e45..b363342d76b0b1a09b607c2d866c47f0bf991b92 100644 (file)
@@ -204,7 +204,7 @@ namespace go
                        if ( !Visible )\r
                                return;\r
 \r
-                       if (bmp == null)\r
+                       if (cacheIsEmpty)\r
                                UpdateGraphic ();\r
                        else {\r
 \r
@@ -223,9 +223,13 @@ namespace go
                                if (!DrawingIsValid || clip != null) {//false when 1 child has changed\r
                                        //child having their content changed has to be repainted\r
                                        //and those with slot intersecting clip rectangle have also to be repainted\r
-\r
-                                       using (ImageSurface cache =\r
-                                                     new ImageSurface (bmp, Format.Argb32, Slot.Width, Slot.Height, Slot.Width * 4)) {\r
+                                       #if CAIRO_GL\r
+                                       using (Surface cache = new GLSurface\r
+                                               (device, Content.ColorAlpha, texID, Slot.Width, Slot.Height)) {\r
+                                       #else\r
+                                       using (Surface cache =\r
+                                                       new ImageSurface(bmp, Format.Argb32, Slot.Width, Slot.Height, 4 * Slot.Width)) {\r
+                                       #endif\r
                                                Context gr = new Context (cache);\r
                                                clip.clearAndClip (gr);\r
 \r
index e62613d1b6d19229d55dbeec449e468e848bd09d..af3d25c261b7336e16208bbdb5304445768f4a68 100644 (file)
@@ -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;
index 5fbcd9c19a847a15f3c026065afa7716f5ccf4de..ebe0c2df95d22d76c023d3d066d31e25240c85cf 100755 (executable)
@@ -27,7 +27,7 @@ namespace go
                public OpenTKGameWindow(int _width, int _height, string _title="golib")\r
                        : base(_width, _height, new OpenTK.Graphics.GraphicsMode(32, 24, 0, 1), \r
                                _title,GameWindowFlags.Default,DisplayDevice.GetDisplay(DisplayIndex.Second),\r
-                               3,3,OpenTK.Graphics.GraphicsContextFlags.Debug)\r
+                               3,3,OpenTK.Graphics.GraphicsContextFlags.Default)\r
 //             public OpenTKGameWindow(int _width, int _height, string _title="golib")\r
 //                     : base(_width, _height, new OpenTK.Graphics.GraphicsMode(32, 24, 0, 8), _title)\r
                {\r
@@ -158,8 +158,14 @@ namespace go
                #region graphic contexte\r
                Context ctx;\r
                Surface surf;\r
+               #if CAIRO_GL\r
+               public Device device;\r
+               OpenTK.Graphics.IGraphicsContext cairoGLContext;\r
+               #else\r
                byte[] bmp;\r
-               int texID;\r
+               #endif\r
+\r
+               uint texID;\r
 \r
                public QuadVAO uiQuad, uiQuad2;\r
                go.GLBackend.Shader shader;\r
@@ -167,9 +173,17 @@ namespace go
 \r
                Rectangle dirtyZone = Rectangle.Empty;\r
                void createContext()\r
-               {                       \r
+               {\r
+                       #if CAIRO_GL\r
+                       cairoGLContext.MakeCurrent(this.WindowInfo);\r
+                       #endif\r
+\r
                        createOpenGLSurface ();\r
 \r
+                       #if CAIRO_GL\r
+                       this.MakeCurrent();\r
+                       #endif\r
+\r
                        if (uiQuad != null)\r
                                uiQuad.Dispose ();\r
                        uiQuad = new QuadVAO (0, 0, ClientRectangle.Width, ClientRectangle.Height, 0, 1, 1, -1);\r
@@ -179,15 +193,13 @@ namespace go
                                (0, ClientRectangle.Width, ClientRectangle.Height, 0, 0, 1);                    \r
 \r
                        redrawClip.AddRectangle (ClientRectangle);\r
+\r
+\r
                }\r
                void createOpenGLSurface()\r
                {\r
                        currentWindow = this;\r
 \r
-                       int stride = 4 * ClientRectangle.Width;\r
-                       int bmpSize = Math.Abs (stride) * ClientRectangle.Height;\r
-                       bmp = new byte[bmpSize];\r
-\r
                        //create texture\r
                        if (GL.IsTexture(texID))\r
                                GL.DeleteTexture (texID);\r
@@ -195,16 +207,29 @@ namespace go
                        GL.ActiveTexture (TextureUnit.Texture0);\r
                        GL.BindTexture(TextureTarget.Texture2D, texID);\r
 \r
+                       #if CAIRO_GL\r
+                       if (surf != null)\r
+                               surf.Dispose();                 \r
+                       GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, \r
+                               ClientRectangle.Width, ClientRectangle.Height, 0,\r
+                               OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero);\r
+                       surf = new Cairo.GLSurface (device, Cairo.Content.ColorAlpha, texID, \r
+                               ClientRectangle.Width, ClientRectangle.Height);\r
+                       #else\r
+                       int stride = 4 * ClientRectangle.Width;\r
+                       int bmpSize = Math.Abs (stride) * ClientRectangle.Height;\r
+                       bmp = new byte[bmpSize];\r
+\r
                        GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, \r
                                ClientRectangle.Width, ClientRectangle.Height, 0,\r
                                OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bmp);\r
 \r
                        GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);\r
                        GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);\r
-\r
+                       #endif\r
                        GL.BindTexture(TextureTarget.Texture2D, 0);\r
 \r
-                       shader.Texture = texID;\r
+                       shader.Texture = (int)texID;\r
                }\r
                void OpenGLDraw()\r
                {\r
@@ -213,10 +238,12 @@ namespace go
 \r
                        shader.Enable ();\r
 \r
+                       #if CAIRO_GL\r
+                       #else\r
                        GL.TexSubImage2D (TextureTarget.Texture2D, 0,\r
                                0, 0, ClientRectangle.Width, ClientRectangle.Height,\r
                                OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bmp);\r
-\r
+                       #endif\r
                        uiQuad.Render (PrimitiveType.TriangleStrip);\r
 \r
                        GL.BindTexture(TextureTarget.Texture2D, 0);\r
@@ -224,23 +251,7 @@ namespace go
                        shader.Disable ();\r
                        GL.Viewport (viewport [0], viewport [1], viewport [2], viewport [3]);\r
                }\r
-//             public void RenderCustomTextureOnUIQuad(int _customTex)\r
-//             {\r
-//                     GL.GetInteger (GetPName.Viewport, viewport);\r
-//                     GL.Viewport (0, 0, ClientRectangle.Width, ClientRectangle.Height);\r
-//\r
-//                     shader.Enable ();\r
-//\r
-//                     GL.ActiveTexture (TextureUnit.Texture0);\r
-//                     GL.BindTexture (TextureTarget.Texture2D, _customTex);\r
-//                     GL.Disable (EnableCap.DepthTest);\r
-//                     uiQuad2.Render (PrimitiveType.TriangleStrip);\r
-//                     GL.Enable (EnableCap.DepthTest);\r
-//                     GL.BindTexture(TextureTarget.Texture2D, 0);\r
-//                     shader.Disable ();\r
-//                     GL.Viewport (viewport [0], viewport [1], viewport [2], viewport [3]);                   \r
-//             }\r
-                       \r
+\r
                #endregion\r
 \r
                #region update\r
@@ -256,7 +267,13 @@ namespace go
                        guTime.Reset ();\r
                        drawingTime.Reset ();\r
 \r
+                       #if CAIRO_GL\r
+                       GraphicObject.device = device;\r
+                       cairoGLContext.MakeCurrent(this.WindowInfo);\r
+                       #else\r
                        surf = new ImageSurface(bmp, Format.Argb32, ClientRectangle.Width, ClientRectangle.Height,ClientRectangle.Width*4);\r
+                       #endif\r
+\r
                        ctx = new Context(surf);\r
 \r
                        if (Interface.LoadingLists.Count > 0) {\r
@@ -329,9 +346,17 @@ namespace go
                                        redrawClip.Reset ();\r
                                }\r
                        }\r
+                       surf.Flush ();\r
                        //surf.WriteToPng (@"/mnt/data/test.png");\r
                        ctx.Dispose ();\r
+                       #if CAIRO_GL\r
+                       this.MakeCurrent ();\r
+                       #else\r
                        surf.Dispose ();\r
+                       #endif\r
+\r
+\r
+\r
 //                     if (ToolTip.isVisible) {\r
 //                             ToolTip.panel.processkLayouting();\r
 //                             if (ToolTip.panel.layoutIsValid)\r
@@ -379,7 +404,6 @@ namespace go
                {\r
                        GLClear ();\r
 \r
-\r
                        base.OnRenderFrame(e);\r
 \r
                        OnRender (e);\r
@@ -410,6 +434,14 @@ namespace go
                        int mts = GL.GetInteger (GetPName.MaxTextureSize);\r
 \r
                        shader = new go.GLBackend.TexturedShader ();\r
+\r
+                       #if CAIRO_GL\r
+                       cairoGLContext = OpenTK.Platform.Utilities.CloneGLContext (this);\r
+                       IntPtr dpy = OpenTK.Platform.Utilities.GetDisplay(this.WindowInfo);\r
+                       cairoGLContext.MakeCurrent(this.WindowInfo);\r
+                       device = new Cairo.Device (dpy, \r
+                               (cairoGLContext as OpenTK.Graphics.IGraphicsContextInternal).Context.Handle);                   \r
+                       #endif\r
                }\r
 \r
                protected override void OnResize(EventArgs e)\r