[cogl/wip/cogl-sharp: 38/43] cogl-sharp: Expose CoglPipeline



commit 634d81567670f0b7684906a755c959af1e3121ab
Author: Damien Lespiau <damien lespiau intel com>
Date:   Mon Oct 1 22:09:58 2012 +0100

    cogl-sharp: Expose CoglPipeline
    
    To do so, 2 small features in parse-gir.py:
      - a way to blacklist methods we cannot generate yet
      - support for object return types (where you need to create a new
        wrapper object around a CoglObject)

 cogl-sharp/Makefile.am     |    2 +
 cogl-sharp/Pipeline.cs     |   35 +++++++++++
 cogl-sharp/_FrameBuffer.cs |   24 ++++++++
 cogl-sharp/_Pipeline.cs    |  139 ++++++++++++++++++++++++++++++++++++++++++++
 cogl-sharp/parse-gir.py    |   40 +++++++++++--
 5 files changed, 234 insertions(+), 6 deletions(-)
---
diff --git a/cogl-sharp/Makefile.am b/cogl-sharp/Makefile.am
index 8530030..7e9f953 100644
--- a/cogl-sharp/Makefile.am
+++ b/cogl-sharp/Makefile.am
@@ -18,6 +18,8 @@ sources =		\
 	Matrix.cs	\
 	Object.cs	\
 	OnScreen.cs	\
+	Pipeline.cs	\
+	_Pipeline.cs	\
 	PixelFormat.cs	\
 	AssemblyInfo.cs	\
 	$(NULL)
diff --git a/cogl-sharp/Pipeline.cs b/cogl-sharp/Pipeline.cs
new file mode 100644
index 0000000..a6d2a02
--- /dev/null
+++ b/cogl-sharp/Pipeline.cs
@@ -0,0 +1,35 @@
+/*
+ * 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 partial class Pipeline : Cogl.Object
+    {
+        public Pipeline(IntPtr h) : base(h) {}
+    }
+}
diff --git a/cogl-sharp/_FrameBuffer.cs b/cogl-sharp/_FrameBuffer.cs
index d100c19..aa2ceb3 100644
--- a/cogl-sharp/_FrameBuffer.cs
+++ b/cogl-sharp/_FrameBuffer.cs
@@ -31,6 +31,30 @@ namespace Cogl
         }
 
         [DllImport("cogl2.dll")]
+        public static extern void cogl_framebuffer_draw_multitextured_rectangle(IntPtr o, IntPtr pipeline, float x_1, float y_1, float x_2, float y_2, float tex_coords, int tex_coords_len);
+
+        public void DrawMultitexturedRectangle(Pipeline pipeline, float x_1, float y_1, float x_2, float y_2, float tex_coords, int tex_coords_len)
+        {
+            cogl_framebuffer_draw_multitextured_rectangle(handle, pipeline.Handle, x_1, y_1, x_2, y_2, tex_coords, tex_coords_len);
+        }
+
+        [DllImport("cogl2.dll")]
+        public static extern void cogl_framebuffer_draw_rectangle(IntPtr o, IntPtr pipeline, float x_1, float y_1, float x_2, float y_2);
+
+        public void DrawRectangle(Pipeline pipeline, float x_1, float y_1, float x_2, float y_2)
+        {
+            cogl_framebuffer_draw_rectangle(handle, pipeline.Handle, x_1, y_1, x_2, y_2);
+        }
+
+        [DllImport("cogl2.dll")]
+        public static extern void cogl_framebuffer_draw_textured_rectangle(IntPtr o, IntPtr pipeline, float x_1, float y_1, float x_2, float y_2, float s_1, float t_1, float s_2, float t_2);
+
+        public void DrawTexturedRectangle(Pipeline pipeline, float x_1, float y_1, float x_2, float y_2, float s_1, float t_1, float s_2, float t_2)
+        {
+            cogl_framebuffer_draw_textured_rectangle(handle, pipeline.Handle, x_1, y_1, x_2, y_2, s_1, t_1, s_2, t_2);
+        }
+
+        [DllImport("cogl2.dll")]
         public static extern void cogl_framebuffer_finish(IntPtr o);
 
         public void Finish()
diff --git a/cogl-sharp/_Pipeline.cs b/cogl-sharp/_Pipeline.cs
new file mode 100644
index 0000000..39e8813
--- /dev/null
+++ b/cogl-sharp/_Pipeline.cs
@@ -0,0 +1,139 @@
+/* This file has been generated by parse-gir.py, do not hand edit */
+using System;
+using System.Runtime.InteropServices;
+
+namespace Cogl
+{
+    public partial class Pipeline
+    {
+        [DllImport("cogl2.dll")]
+        public static extern IntPtr cogl_pipeline_copy(IntPtr o);
+
+        public Pipeline Copy()
+        {
+            IntPtr p = cogl_pipeline_copy(handle);
+            return new Pipeline(p);
+        }
+
+        [DllImport("cogl2.dll")]
+        public static extern float cogl_pipeline_get_alpha_test_reference(IntPtr o);
+
+        public float GetAlphaTestReference()
+        {
+            return cogl_pipeline_get_alpha_test_reference(handle);
+        }
+
+        [DllImport("cogl2.dll")]
+        public static extern void cogl_pipeline_get_color(IntPtr o);
+
+        public void GetColor()
+        {
+            cogl_pipeline_get_color(handle);
+        }
+
+        [DllImport("cogl2.dll")]
+        public static extern ColorMask cogl_pipeline_get_color_mask(IntPtr o);
+
+        public ColorMask GetColorMask()
+        {
+            return cogl_pipeline_get_color_mask(handle);
+        }
+
+        [DllImport("cogl2.dll")]
+        public static extern int cogl_pipeline_get_n_layers(IntPtr o);
+
+        public int GetNLayers()
+        {
+            return cogl_pipeline_get_n_layers(handle);
+        }
+
+        [DllImport("cogl2.dll")]
+        public static extern float cogl_pipeline_get_point_size(IntPtr o);
+
+        public float GetPointSize()
+        {
+            return cogl_pipeline_get_point_size(handle);
+        }
+
+        [DllImport("cogl2.dll")]
+        public static extern void cogl_pipeline_remove_layer(IntPtr o, int layer_index);
+
+        public void RemoveLayer(int layer_index)
+        {
+            cogl_pipeline_remove_layer(handle, layer_index);
+        }
+
+        [DllImport("cogl2.dll")]
+        public static extern void cogl_pipeline_set_blend_constant(IntPtr o, ref Color constant_color);
+
+        public void SetBlendConstant(ref Color constant_color)
+        {
+            cogl_pipeline_set_blend_constant(handle, ref constant_color);
+        }
+
+        [DllImport("cogl2.dll")]
+        public static extern void cogl_pipeline_set_color(IntPtr o, ref Color color);
+
+        public void SetColor(ref Color color)
+        {
+            cogl_pipeline_set_color(handle, ref color);
+        }
+
+        [DllImport("cogl2.dll")]
+        public static extern void cogl_pipeline_set_color4f(IntPtr o, float red, float green, float blue, float alpha);
+
+        public void SetColor4f(float red, float green, float blue, float alpha)
+        {
+            cogl_pipeline_set_color4f(handle, red, green, blue, alpha);
+        }
+
+        [DllImport("cogl2.dll")]
+        public static extern void cogl_pipeline_set_color_mask(IntPtr o, ColorMask color_mask);
+
+        public void SetColorMask(ColorMask color_mask)
+        {
+            cogl_pipeline_set_color_mask(handle, color_mask);
+        }
+
+        [DllImport("cogl2.dll")]
+        public static extern void cogl_pipeline_set_layer_combine_constant(IntPtr o, int layer_index, ref Color constant);
+
+        public void SetLayerCombineConstant(int layer_index, ref Color constant)
+        {
+            cogl_pipeline_set_layer_combine_constant(handle, layer_index, ref constant);
+        }
+
+        [DllImport("cogl2.dll")]
+        public static extern void cogl_pipeline_set_layer_matrix(IntPtr o, int layer_index, ref Matrix matrix);
+
+        public void SetLayerMatrix(int layer_index, ref Matrix matrix)
+        {
+            cogl_pipeline_set_layer_matrix(handle, layer_index, ref matrix);
+        }
+
+        [DllImport("cogl2.dll")]
+        public static extern void cogl_pipeline_set_point_size(IntPtr o, float point_size);
+
+        public void SetPointSize(float point_size)
+        {
+            cogl_pipeline_set_point_size(handle, point_size);
+        }
+
+        [DllImport("cogl2.dll")]
+        public static extern void cogl_pipeline_set_uniform_1f(IntPtr o, int uniform_location, float value);
+
+        public void SetUniform1f(int uniform_location, float value)
+        {
+            cogl_pipeline_set_uniform_1f(handle, uniform_location, value);
+        }
+
+        [DllImport("cogl2.dll")]
+        public static extern void cogl_pipeline_set_uniform_1i(IntPtr o, int uniform_location, int value);
+
+        public void SetUniform1i(int uniform_location, int value)
+        {
+            cogl_pipeline_set_uniform_1i(handle, uniform_location, value);
+        }
+
+    }
+}
diff --git a/cogl-sharp/parse-gir.py b/cogl-sharp/parse-gir.py
index ee2b59a..08379f7 100755
--- a/cogl-sharp/parse-gir.py
+++ b/cogl-sharp/parse-gir.py
@@ -14,7 +14,8 @@ enum_types = (
 
 # object types to dump (.gir names)
 object_types = (
-    "Framebuffer"
+    "Framebuffer",
+    "Pipeline",
 )
 
 # The struct types (value types) are written by hand
@@ -37,6 +38,11 @@ name_overrides = {
     'Offscreen': {
         'class': 'OffScreen'
     },
+    'Pipeline': {
+        'blacklist': (
+            'set_uniform_float', 'set_uniform_int'
+        )
+    },
     'PixelFormat': {
         'uppercase': 1
     }
@@ -159,16 +165,30 @@ def derive_cs_type(gir_type, c_type):
 
     return gir_type
 
+def is_blacklisted(gir_name, overrides):
+    if not overrides:
+        return False
+
+    if not 'blacklist' in overrides:
+        return False
+
+    return gir_name in overrides['blacklist']
+
 def generate_method(node, overrides, fo):
+    gir_name = node.getAttribute("name")
 
     native_method_name = node.getAttributeNS(C_NS, "identifier")
     native_return_value = "void"
     native_params = ['IntPtr o']
-    cs_method_name = make_method_name(node.getAttribute("name"))
+    cs_method_name = make_method_name(gir_name)
     cs_return_value = "void"
     cs_params = []
     call_params = ['handle']
 
+    if is_blacklisted(gir_name, overrides):
+        print("  Skipping %s, blacklisted" % cs_method_name)
+        return
+
     # Let's figure out if we can generate that method (ie if we know how to
     # handle the types of the return value and of the parameters).
     # At the same time, we compute the nececessary return value and parameter
@@ -190,6 +210,8 @@ def generate_method(node, overrides, fo):
     native_return_value = derive_native_type(return_type_name, return_c_type)
     cs_return_value = derive_cs_type(return_type_name, return_c_type)
 
+    return_object = return_type_name in object_types
+
     # ... then the parameters
     params_list = node.getElementsByTagName("parameters")
     assert len(params_list) <= 1
@@ -224,7 +246,8 @@ def generate_method(node, overrides, fo):
             t = derive_cs_type(gir_type, c_type)
             cs_params.append(ref + t + ' ' + param_name)
 
-            call_params.append(ref + param_name)
+            handle = '.Handle' if gir_type in object_types else ''
+            call_params.append(ref + param_name + handle)
 
     if not generatable:
         return
@@ -238,8 +261,13 @@ def generate_method(node, overrides, fo):
     fo.write("        public %s %s(%s)\n" %
              (cs_return_value, cs_method_name, ", ".join(cs_params)))
     fo.write("        {\n")
-    fo.write("            %s%s(%s);\n" %
-             (return_str, native_method_name, ", ".join(call_params)))
+    if not return_object:
+        fo.write("            %s%s(%s);\n" %
+                 (return_str, native_method_name, ", ".join(call_params)))
+    else:
+        fo.write("            IntPtr p = %s(%s);\n" %
+                 (native_method_name, ", ".join(call_params)))
+        fo.write("            return new %s(p);\n" % cs_return_value)
     fo.write("        }\n\n")
 
 def generate_classes(doc):
@@ -251,7 +279,7 @@ def generate_classes(doc):
         overrides = None
         if type_name in name_overrides:
             overrides = name_overrides[type_name]
-        if 'class' in overrides:
+        if overrides and 'class' in overrides:
             type_name = overrides['class']
 
         print("Generate _%s" % type_name + ".cs")



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]