[cogl/wip/rib/master-next: 37/44] framebuffer: adds cogl_framebuffer_get_samples_per_pixel



commit a30fee2d16961decd5628f7e9cbab443a2c2558f
Author: Robert Bragg <robert linux intel com>
Date:   Sat Oct 8 15:47:42 2011 +0100

    framebuffer: adds cogl_framebuffer_get_samples_per_pixel
    
    It's useful to be able to query back the number of
    point_samples_per_pixel that may have previously be chosen using
    cogl_framebuffer_set_samples_per_pixel().

 cogl/cogl-framebuffer-private.h                    |    2 +
 cogl/cogl-framebuffer.c                            |   29 +++++++++++++++++++
 cogl/cogl-framebuffer.h                            |   30 ++++++++++++++++++++
 cogl/winsys/cogl-winsys-egl.c                      |   12 ++++++++
 cogl/winsys/cogl-winsys-glx.c                      |   13 ++++++++
 .../cogl-2.0-experimental-sections.txt             |    2 +
 6 files changed, 88 insertions(+), 0 deletions(-)
---
diff --git a/cogl/cogl-framebuffer-private.h b/cogl/cogl-framebuffer-private.h
index a6f8e16..e168b6e 100644
--- a/cogl/cogl-framebuffer-private.h
+++ b/cogl/cogl-framebuffer-private.h
@@ -91,6 +91,8 @@ struct _CoglFramebuffer
   gboolean            dither_enabled;
   CoglColorMask       color_mask;
 
+  int                 samples_per_pixel;
+
   /* We journal the textured rectangles we want to submit to OpenGL so
    * we have an oppertunity to batch them together into less draw
    * calls. */
diff --git a/cogl/cogl-framebuffer.c b/cogl/cogl-framebuffer.c
index 5116f10..3144c95 100644
--- a/cogl/cogl-framebuffer.c
+++ b/cogl/cogl-framebuffer.c
@@ -92,6 +92,9 @@
 #ifndef GL_DRAW_FRAMEBUFFER
 #define GL_DRAW_FRAMEBUFFER               0x8CA9
 #endif
+#ifndef GL_TEXTURE_SAMPLES_IMG
+#define GL_TEXTURE_SAMPLES_IMG            0x9136
+#endif
 
 typedef enum {
   _TRY_DEPTH_STENCIL = 1L<<0,
@@ -163,6 +166,8 @@ _cogl_framebuffer_init (CoglFramebuffer *framebuffer,
 
   framebuffer->color_mask       = COGL_COLOR_MASK_ALL;
 
+  framebuffer->samples_per_pixel = 0;
+
   /* Initialise the clip stack */
   _cogl_clip_state_init (&framebuffer->clip_state);
 
@@ -941,6 +946,21 @@ try_creating_fbo (CoglOffscreen *offscreen,
       return FALSE;
     }
 
+  /* Update the real number of samples_per_pixel now that we have a
+   * complete framebuffer */
+  if (n_samples)
+    {
+      GLenum attachment = GL_COLOR_ATTACHMENT0;
+      GLenum pname = GL_TEXTURE_SAMPLES_IMG;
+      int texture_samples;
+
+      GE( ctx, glGetFramebufferAttachmentParameteriv (GL_FRAMEBUFFER,
+                                                      attachment,
+                                                      pname,
+                                                      &texture_samples) );
+      fb->samples_per_pixel = texture_samples;
+    }
+
   return TRUE;
 }
 
@@ -1526,6 +1546,15 @@ cogl_framebuffer_get_color_format (CoglFramebuffer *framebuffer)
   return framebuffer->format;
 }
 
+int
+cogl_framebuffer_get_samples_per_pixel (CoglFramebuffer *framebuffer)
+{
+  if (framebuffer->allocated)
+    return framebuffer->samples_per_pixel;
+  else
+    return framebuffer->config.samples_per_pixel;
+}
+
 void
 cogl_framebuffer_set_samples_per_pixel (CoglFramebuffer *framebuffer,
                                         int samples_per_pixel)
diff --git a/cogl/cogl-framebuffer.h b/cogl/cogl-framebuffer.h
index 48f888e..1234b36 100644
--- a/cogl/cogl-framebuffer.h
+++ b/cogl/cogl-framebuffer.h
@@ -326,6 +326,36 @@ void
 cogl_framebuffer_set_samples_per_pixel (CoglFramebuffer *framebuffer,
                                         int samples_per_pixel);
 
+#define cogl_framebuffer_get_samples_per_pixel \
+  cogl_framebuffer_get_samples_per_pixel_EXP
+/**
+ * cogl_framebuffer_get_samples_per_pixel:
+ * @framebuffer: A #CoglFramebuffer framebuffer
+ *
+ * Gets the number of points that are sampled per-pixel when
+ * rasterizing geometry. Usually by default this will return 0 which
+ * means that single-sample not multisample rendering has been chosen.
+ * When using a GPU supporting multisample rendering it's possible to
+ * increase the number of samples per pixel using
+ * cogl_framebuffer_set_samples_per_pixel().
+ *
+ * Calling cogl_framebuffer_get_samples_per_pixel() before the
+ * framebuffer has been allocated will simply return the value set
+ * using cogl_framebuffer_set_samples_per_pixel(). After the
+ * framebuffer has been allocated the value will reflect the actual
+ * number of samples that will be made by the GPU.
+ *
+ * Returns: The number of point samples made per pixel when
+ *          rasterizing geometry or 0 if single-sample rendering
+ *          has been chosen.
+ *
+ * Since: 1.10
+ * Stability: unstable
+ */
+int
+cogl_framebuffer_get_samples_per_pixel (CoglFramebuffer *framebuffer);
+
+
 #define cogl_framebuffer_resolve_samples \
   cogl_framebuffer_resolve_samples_EXP
 /**
diff --git a/cogl/winsys/cogl-winsys-egl.c b/cogl/winsys/cogl-winsys-egl.c
index b418aa1..c7dc3e6 100644
--- a/cogl/winsys/cogl-winsys-egl.c
+++ b/cogl/winsys/cogl-winsys-egl.c
@@ -1251,6 +1251,18 @@ _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
       return FALSE;
     }
 
+  /* Update the real number of samples_per_pixel now that we have
+   * found an egl_config... */
+  if (framebuffer->config.samples_per_pixel)
+    {
+      EGLint samples;
+      status = eglGetConfigAttrib (egl_renderer->edpy,
+                                   egl_config,
+                                   EGL_SAMPLES, &samples);
+      g_return_val_if_fail (status == EGL_TRUE, TRUE);
+      framebuffer->samples_per_pixel = samples;
+    }
+
 #ifdef COGL_HAS_EGL_PLATFORM_POWERVR_X11_SUPPORT
 
   /* FIXME: We need to explicitly Select for ConfigureNotify events.
diff --git a/cogl/winsys/cogl-winsys-glx.c b/cogl/winsys/cogl-winsys-glx.c
index dec96a1..cd67b00 100644
--- a/cogl/winsys/cogl-winsys-glx.c
+++ b/cogl/winsys/cogl-winsys-glx.c
@@ -818,6 +818,19 @@ _cogl_winsys_onscreen_init (CoglOnscreen *onscreen,
       return FALSE;
     }
 
+  /* Update the real number of samples_per_pixel now that we have
+   * found an fbconfig... */
+  if (framebuffer->config.samples_per_pixel)
+    {
+      int samples;
+      int status = glx_renderer->glXGetFBConfigAttrib (xlib_renderer->xdpy,
+                                                       fbconfig,
+                                                       GLX_SAMPLES,
+                                                       &samples);
+      g_return_val_if_fail (status == Success, TRUE);
+      framebuffer->samples_per_pixel = samples;
+    }
+
   /* FIXME: We need to explicitly Select for ConfigureNotify events.
    * For foreign windows we need to be careful not to mess up any
    * existing event mask.
diff --git a/doc/reference/cogl-2.0-experimental/cogl-2.0-experimental-sections.txt b/doc/reference/cogl-2.0-experimental/cogl-2.0-experimental-sections.txt
index 6aa3945..c65582a 100644
--- a/doc/reference/cogl-2.0-experimental/cogl-2.0-experimental-sections.txt
+++ b/doc/reference/cogl-2.0-experimental/cogl-2.0-experimental-sections.txt
@@ -348,6 +348,8 @@ cogl_framebuffer_get_blue_bits
 cogl_framebuffer_get_blue_bits
 cogl_framebuffer_get_color_mask
 cogl_framebuffer_set_color_mask
+cogl_framebuffer_get_point_samples_per_pixel
+cogl_framebuffer_set_point_samples_per_pixel
 cogl_framebuffer_get_context
 cogl_framebuffer_clear
 cogl_framebuffer_clear4f



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