glformat: define our own set of formats from the GL defines
authorMatthew Waters <matthew@centricular.com>
Mon, 11 Jul 2016 12:28:42 +0000 (22:28 +1000)
committerTim-Philipp Müller <tim@centricular.com>
Sat, 9 Dec 2017 19:32:21 +0000 (19:32 +0000)
also add some depth/stencil formats

gst-libs/gst/gl/gstglformat.c
gst-libs/gst/gl/gstglformat.h

index 237e250..1a71327 100644 (file)
 #define USING_GLES2(context) (gst_gl_context_check_gl_version (context, GST_GL_API_GLES2, 2, 0))
 #define USING_GLES3(context) (gst_gl_context_check_gl_version (context, GST_GL_API_GLES2, 3, 0))
 
-#ifndef GL_RGBA8
-#define GL_RGBA8 0x8058
-#endif
-#ifndef GL_RED
-#define GL_RED 0x1903
-#endif
-#ifndef GL_RG
-#define GL_RG 0x8227
-#endif
-#ifndef GL_R8
-#define GL_R8 0x8229
-#endif
-#ifndef GL_RG8
-#define GL_RG8 0x822B
-#endif
-
 #ifndef GL_TEXTURE_RECTANGLE
 #define GL_TEXTURE_RECTANGLE 0x84F5
 #endif
@@ -59,21 +43,21 @@ _gl_format_n_components (guint format)
 {
   switch (format) {
     case GST_VIDEO_GL_TEXTURE_TYPE_RGBA:
-    case GL_RGBA:
+    case GST_GL_RGBA:
       return 4;
     case GST_VIDEO_GL_TEXTURE_TYPE_RGB:
     case GST_VIDEO_GL_TEXTURE_TYPE_RGB16:
-    case GL_RGB:
+    case GST_GL_RGB:
       return 3;
     case GST_VIDEO_GL_TEXTURE_TYPE_LUMINANCE_ALPHA:
     case GST_VIDEO_GL_TEXTURE_TYPE_RG:
-    case GL_LUMINANCE_ALPHA:
-    case GL_RG:
+    case GST_GL_LUMINANCE_ALPHA:
+    case GST_GL_RG:
       return 2;
     case GST_VIDEO_GL_TEXTURE_TYPE_LUMINANCE:
     case GST_VIDEO_GL_TEXTURE_TYPE_R:
-    case GL_LUMINANCE:
-    case GL_RED:
+    case GST_GL_LUMINANCE:
+    case GST_GL_RED:
       return 1;
     default:
       return 0;
@@ -153,20 +137,20 @@ gst_gl_format_from_gl_texture_type (GstVideoGLTextureType tex_format)
 {
   switch (tex_format) {
     case GST_VIDEO_GL_TEXTURE_TYPE_LUMINANCE_ALPHA:
-      return GL_LUMINANCE_ALPHA;
+      return GST_GL_LUMINANCE_ALPHA;
     case GST_VIDEO_GL_TEXTURE_TYPE_LUMINANCE:
-      return GL_LUMINANCE;
+      return GST_GL_LUMINANCE;
     case GST_VIDEO_GL_TEXTURE_TYPE_RGBA:
-      return GL_RGBA;
+      return GST_GL_RGBA;
     case GST_VIDEO_GL_TEXTURE_TYPE_RGB:
     case GST_VIDEO_GL_TEXTURE_TYPE_RGB16:
-      return GL_RGB;
+      return GST_GL_RGB;
     case GST_VIDEO_GL_TEXTURE_TYPE_RG:
-      return GL_RG;
+      return GST_GL_RG;
     case GST_VIDEO_GL_TEXTURE_TYPE_R:
-      return GL_RED;
+      return GST_GL_RED;
     default:
-      return GST_VIDEO_GL_TEXTURE_TYPE_RGBA;
+      return tex_format;
   }
 }
 
@@ -273,51 +257,52 @@ gst_gl_sized_gl_format_from_gl_format_type (GstGLContext * context,
       gst_gl_context_check_feature (context, "GL_EXT_texture_rg");
 
   switch (format) {
-    case GL_RGBA:
+    case GST_GL_RGBA:
       switch (type) {
         case GL_UNSIGNED_BYTE:
           return USING_GLES2 (context)
-              && !USING_GLES3 (context) ? GL_RGBA : GL_RGBA8;
+              && !USING_GLES3 (context) ? GST_GL_RGBA : GST_GL_RGBA8;
           break;
       }
       break;
-    case GL_RGB:
+    case GST_GL_RGB:
       switch (type) {
         case GL_UNSIGNED_BYTE:
-          return GL_RGB8;
+          return GST_GL_RGB8;
           break;
         case GL_UNSIGNED_SHORT_5_6_5:
-          return GL_RGB;
+          return GST_GL_RGB;
           break;
       }
       break;
-    case GL_RG:
+    case GST_GL_RG:
       switch (type) {
         case GL_UNSIGNED_BYTE:
           if (!USING_GLES3 (context) && USING_GLES2 (context) && ext_texture_rg)
-            return GL_RG;
-          return GL_RG8;
+            return GST_GL_RG;
+          return GST_GL_RG8;
           break;
       }
       break;
-    case GL_RED:
+    case GST_GL_RED:
       switch (type) {
         case GL_UNSIGNED_BYTE:
           if (!USING_GLES3 (context) && USING_GLES2 (context) && ext_texture_rg)
-            return GL_RED;
-          return GL_R8;
+            return GST_GL_RED;
+          return GST_GL_R8;
           break;
       }
       break;
-    case GL_LUMINANCE:
-      return GL_LUMINANCE;
-      break;
-    case GL_LUMINANCE_ALPHA:
-      return GL_LUMINANCE_ALPHA;
-      break;
-    case GL_ALPHA:
-      return GL_ALPHA;
-      break;
+    case GST_GL_RGBA8:
+    case GST_GL_RGB8:
+    case GST_GL_RG8:
+    case GST_GL_R8:
+    case GST_GL_LUMINANCE:
+    case GST_GL_LUMINANCE_ALPHA:
+    case GST_GL_ALPHA:
+    case GST_GL_DEPTH_COMPONENT16:
+    case GST_GL_DEPTH24_STENCIL8:
+      return format;
     default:
       break;
   }
index fcd618a..e4e6e37 100644 (file)
 
 G_BEGIN_DECLS
 
+typedef enum
+{
+  /* values taken from the GL headers */
+  GST_GL_LUMINANCE                      = 0x1909,
+
+  GST_GL_ALPHA                          = 0x1906,
+
+  GST_GL_LUMINANCE_ALPHA                = 0x190A,
+
+  GST_GL_RED                            = 0x1903,
+  GST_GL_R8                             = 0x8229,
+
+  GST_GL_RG                             = 0x8227,
+  GST_GL_RG8                            = 0x822B,
+
+  GST_GL_RGB                            = 0x1907,
+  GST_GL_RGB8                           = 0x8051,
+  GST_GL_RGB565                         = 0x8D62,
+
+  GST_GL_RGBA                           = 0x1908,
+  GST_GL_RGBA8                          = 0x8058,
+
+  GST_GL_DEPTH_COMPONENT16              = 0x81A5,
+
+  GST_GL_DEPTH24_STENCIL8               = 0x88F0,
+} GstGLFormat;
+
 guint                   gst_gl_format_type_n_bytes                  (guint format,
                                                                      guint type);
 guint                   gst_gl_texture_type_n_bytes                 (GstVideoGLTextureType tex_format);