[cogl/wip/cogl-sharp: 9/51] cogl-sharp: Start looking at exposing Context, FrameBuffer and OnScreen
- From: Damien Lespiau <dlespiau src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [cogl/wip/cogl-sharp: 9/51] cogl-sharp: Start looking at exposing Context, FrameBuffer and OnScreen
- Date: Sat, 5 Jan 2013 16:49:03 +0000 (UTC)
commit a73417339e86e9c5d24fa8356d24cb69b6f634dc
Author: Damien Lespiau <damien lespiau intel com>
Date: Sun Sep 30 18:42:03 2012 +0100
cogl-sharp: Start looking at exposing Context, FrameBuffer and OnScreen
This is by not mean complete but a first stab at looking at what is
needed to bind Cogl to C#.
parse-gir.py is expected to grow a bit to generate the bulk of the
bindings, for now it was used to generate the BufferBit bitfield.
Life cycle of objects is not looked at in details yet.
cogl-sharp/BufferBit.cs | 13 +++++++++
cogl-sharp/Context.cs | 45 +++++++++++++++++++++++++++++++++
cogl-sharp/FrameBuffer.cs | 47 +++++++++++++++++++++++++++++++++++
cogl-sharp/Makefile.am | 5 +++
cogl-sharp/Object.cs | 58 +++++++++++++++++++++++++++++++++++++++++++
cogl-sharp/OnScreen.cs | 60 +++++++++++++++++++++++++++++++++++++++++++++
cogl-sharp/parse-gir.py | 51 ++++++++++++++++++++++++++++++++++++++
7 files changed, 279 insertions(+), 0 deletions(-)
---
diff --git a/cogl-sharp/BufferBit.cs b/cogl-sharp/BufferBit.cs
new file mode 100644
index 0000000..ad1a4d6
--- /dev/null
+++ b/cogl-sharp/BufferBit.cs
@@ -0,0 +1,13 @@
+/* This file is generated by parse-gir.py, do not hand edit */
+using System;
+
+namespace Cogl
+{
+ [Flags]
+ public enum BufferBit
+ {
+ Color = 1,
+ Depth = 2,
+ Stencil = 4
+ }
+}
diff --git a/cogl-sharp/Context.cs b/cogl-sharp/Context.cs
new file mode 100644
index 0000000..6665a86
--- /dev/null
+++ b/cogl-sharp/Context.cs
@@ -0,0 +1,45 @@
+/*
+ * Cogl
+ *
+ * An object oriented GL/GLES Abstraction/Utility Layer
+ *
+ * Copyright (C) 2012 Intel Corporation.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Damien Lespiau <damien lespiau intel com>
+ */
+
+using System;
+using System.Runtime.InteropServices;
+
+namespace Cogl
+{
+ public sealed class Context : Cogl.Object
+ {
+
+ public Context(IntPtr h) : base(h) {}
+
+ [DllImport("cogl2.dll")]
+ private static extern IntPtr cogl_context_new(IntPtr display,
+ IntPtr error);
+
+ public Context()
+ {
+ handle = cogl_context_new(IntPtr.Zero, IntPtr.Zero);
+ }
+ }
+}
diff --git a/cogl-sharp/FrameBuffer.cs b/cogl-sharp/FrameBuffer.cs
new file mode 100644
index 0000000..a387655
--- /dev/null
+++ b/cogl-sharp/FrameBuffer.cs
@@ -0,0 +1,47 @@
+/*
+ * Cogl
+ *
+ * An object oriented GL/GLES Abstraction/Utility Layer
+ *
+ * Copyright (C) 2012 Intel Corporation.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Damien Lespiau <damien lespiau intel com>
+ */
+
+using System;
+using System.Runtime.InteropServices;
+
+namespace Cogl
+{
+ public class FrameBuffer : Cogl.Object
+ {
+ public FrameBuffer(IntPtr h) : base(h) {}
+ public FrameBuffer() {}
+
+ [DllImport("cogl2.dll")]
+ private static extern void cogl_framebuffer_clear(IntPtr fb,
+ BufferBit buffers,
+ ref Color color);
+
+ public void Clear(BufferBit buffers, ref Color color)
+ {
+ cogl_framebuffer_clear(handle, buffers, ref color);
+ }
+ }
+
+}
diff --git a/cogl-sharp/Makefile.am b/cogl-sharp/Makefile.am
index 69cabd2..f9395e5 100644
--- a/cogl-sharp/Makefile.am
+++ b/cogl-sharp/Makefile.am
@@ -9,8 +9,13 @@ pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = cogl2-sharp.pc
sources = \
+ BufferBit.cs \
Color.cs \
+ Context.cs \
+ FrameBuffer.cs \
Matrix.cs \
+ Object.cs \
+ OnScreen.cs \
AssemblyInfo.cs \
$(NULL)
diff --git a/cogl-sharp/Object.cs b/cogl-sharp/Object.cs
new file mode 100644
index 0000000..c615d71
--- /dev/null
+++ b/cogl-sharp/Object.cs
@@ -0,0 +1,58 @@
+/*
+ * Cogl
+ *
+ * An object oriented GL/GLES Abstraction/Utility Layer
+ *
+ * Copyright (C) 2012 Intel Corporation.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Damien Lespiau <damien lespiau intel com>
+ */
+
+using System;
+using System.Runtime.InteropServices;
+
+namespace Cogl
+{
+ public class Object : IDisposable
+ {
+ protected IntPtr handle;
+
+ [DllImport("cogl2.dll")]
+ private static extern IntPtr cogl_object_ref(IntPtr o);
+
+ [DllImport("cogl2.dll")]
+ private static extern void cogl_object_unref(IntPtr o);
+
+ public Object() { }
+
+ public Object(IntPtr h)
+ {
+ handle = h;
+ }
+
+ public void Dispose()
+ {
+ cogl_object_unref(handle);
+ }
+
+ public IntPtr Handle
+ {
+ get { return handle; }
+ }
+ }
+}
diff --git a/cogl-sharp/OnScreen.cs b/cogl-sharp/OnScreen.cs
new file mode 100644
index 0000000..dd6d66a
--- /dev/null
+++ b/cogl-sharp/OnScreen.cs
@@ -0,0 +1,60 @@
+/*
+ * Cogl
+ *
+ * An object oriented GL/GLES Abstraction/Utility Layer
+ *
+ * Copyright (C) 2012 Intel Corporation.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Damien Lespiau <damien lespiau intel com>
+ */
+
+using System;
+using System.Runtime.InteropServices;
+
+namespace Cogl
+{
+ public sealed class OnScreen : FrameBuffer
+ {
+ public OnScreen(IntPtr h) : base(h) {}
+
+ [DllImport("cogl2.dll")]
+ private static extern IntPtr cogl_onscreen_new(IntPtr p,
+ int width, int height);
+
+ public OnScreen(Context ctx, int width, int height)
+ {
+ handle = cogl_onscreen_new(ctx.Handle, width, height);
+ }
+
+ [DllImport("cogl2.dll")]
+ private static extern IntPtr cogl_onscreen_show(IntPtr p);
+
+ public void Show()
+ {
+ cogl_onscreen_show(handle);
+ }
+
+ [DllImport("cogl2.dll")]
+ private static extern IntPtr cogl_onscreen_swap_buffers(IntPtr p);
+
+ public void SwapBuffers()
+ {
+ cogl_onscreen_swap_buffers(handle);
+ }
+ }
+}
diff --git a/cogl-sharp/parse-gir.py b/cogl-sharp/parse-gir.py
new file mode 100755
index 0000000..4e45d6e
--- /dev/null
+++ b/cogl-sharp/parse-gir.py
@@ -0,0 +1,51 @@
+#!/usr/bin/env python
+import sys
+import xml.dom.minidom
+from xml.dom.minidom import Node
+
+types = (
+ "BufferBit"
+)
+
+header="""/* This file is generated by parse-gir.py, do not hand edit */
+using System;
+
+namespace Cogl
+{
+"""
+footer="""}
+"""
+
+def make_enum_name(gir_name):
+ return gir_name.capitalize()
+
+def generate_bitfields(doc):
+ for node in doc.getElementsByTagName("bitfield"):
+ type_name = node.getAttribute("name")
+ if type_name not in types:
+ continue
+
+ print("Generate %s" % type_name + ".cs")
+
+ fo = open(type_name + ".cs", "w+")
+ fo.write(header)
+ fo.write(" [Flags]\n")
+ fo.write(" public enum %s\n" % type_name)
+ fo.write(" {\n")
+ members = node.getElementsByTagName("member")
+ n = 1
+ for member in members:
+ member_name = member.getAttribute("name")
+ value = member.getAttribute("value")
+ enum_name = make_enum_name(member_name)
+ if n < len(members):
+ fo.write(" %s = %s,\n" % (enum_name, value))
+ else:
+ fo.write(" %s = %s\n" % (enum_name, value))
+ n += 1
+ fo.write(" }\n")
+ fo.write(footer)
+ fo.close()
+
+doc = xml.dom.minidom.parse(sys.argv[1])
+generate_bitfields(doc)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]