changeset 30951:e76a4f6bfc8d

Implement OpenGL-based YUV to RGB version for Radeon 9200 class cards on OS X.
author reimar
date Sat, 03 Apr 2010 19:58:06 +0000
parents 39d953a7ee22
children 994f301a13f6
files libvo/gl_common.c libvo/gl_common.h
diffstat 2 files changed, 55 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libvo/gl_common.c	Sat Apr 03 14:40:08 2010 +0000
+++ b/libvo/gl_common.c	Sat Apr 03 19:58:06 2010 +0000
@@ -809,6 +809,37 @@
 }
 
 /**
+ * \brief Variant of glYUVSetupCombinersATI using the API
+ *        implemented by Apple.
+ */
+static void glSetupYUVTextFragment(float uvcos, float uvsin) {
+  static const char template[] =
+    "!!ATIfs1.0\n"
+    "StartConstants;\n"
+    "  CONSTANT c0 = {%f, %f, %f};\n"
+    "  CONSTANT c1 = {%f, %f, %f};\n"
+    "EndConstants;\n"
+    "StartOutputPass;\n"
+    "  SampleMap r0, t0.str;\n"
+    "  SampleMap r1, t1.str;\n"
+    "  SampleMap r2, t2.str;\n"
+    "  MUL r1, r1.bias, c0.bias;\n"
+    "  MAD r2.4x, r2.bias, c1.bias, r1;\n"
+    "  ADD r0, r0, r2;\n"
+    "EndPass;\n";
+  GLfloat ucoef[4];
+  GLfloat vcoef[4];
+  char buffer[512];
+
+  fillUVcoeff(ucoef, vcoef, uvcos, uvsin);
+  snprintf(buffer, sizeof(buffer), template,
+           ucoef[0], ucoef[1], ucoef[2],
+           vcoef[0], vcoef[1], vcoef[2]);
+  mp_msg(MSGT_VO, MSGL_DBG2, "[gl] generated fragment program:\n%s\n", buffer);
+  loadGPUProgram(GL_TEXT_FRAGMENT_SHADER_ATI, buffer);
+}
+
+/**
  * \brief helper function for gen_spline_lookup_tex
  * \param x subpixel-position ((0,1) range) to calculate weights for
  * \param dst where to store transformed weights, must provide space for 4 GLfloats
@@ -1346,6 +1377,9 @@
     case YUV_CONVERSION_COMBINERS_ATI:
       glSetupYUVCombinersATI(uvcos, uvsin);
       break;
+    case YUV_CONVERSION_TEXT_FRAGMENT:
+      glSetupYUVTextFragment(uvcos, uvsin);
+      break;
     case YUV_CONVERSION_FRAGMENT_LOOKUP:
     case YUV_CONVERSION_FRAGMENT_LOOKUP3D:
     case YUV_CONVERSION_FRAGMENT:
@@ -1383,6 +1417,14 @@
       mpglActiveTexture(GL_TEXTURE0);
       mpglEnable(GL_FRAGMENT_SHADER_ATI);
       break;
+    case YUV_CONVERSION_TEXT_FRAGMENT:
+      mpglActiveTexture(GL_TEXTURE1);
+      mpglEnable(target);
+      mpglActiveTexture(GL_TEXTURE2);
+      mpglEnable(target);
+      mpglActiveTexture(GL_TEXTURE0);
+      mpglEnable(GL_TEXT_FRAGMENT_SHADER_ATI);
+      break;
     case YUV_CONVERSION_FRAGMENT_LOOKUP3D:
     case YUV_CONVERSION_FRAGMENT_LOOKUP:
     case YUV_CONVERSION_FRAGMENT_POW:
@@ -1417,6 +1459,14 @@
       mpglActiveTexture(GL_TEXTURE0);
       mpglDisable(GL_FRAGMENT_SHADER_ATI);
       break;
+    case YUV_CONVERSION_TEXT_FRAGMENT:
+      mpglActiveTexture(GL_TEXTURE1);
+      mpglDisable(target);
+      mpglActiveTexture(GL_TEXTURE2);
+      mpglDisable(target);
+      mpglActiveTexture(GL_TEXTURE0);
+      mpglDisable(GL_TEXT_FRAGMENT_SHADER_ATI);
+      break;
     case YUV_CONVERSION_FRAGMENT_LOOKUP3D:
     case YUV_CONVERSION_FRAGMENT_LOOKUP:
     case YUV_CONVERSION_FRAGMENT_POW:
--- a/libvo/gl_common.h	Sat Apr 03 14:40:08 2010 +0000
+++ b/libvo/gl_common.h	Sat Apr 03 19:58:06 2010 +0000
@@ -71,6 +71,9 @@
 #ifndef GL_GENERATE_MIPMAP
 #define GL_GENERATE_MIPMAP 0x8191
 #endif
+#ifndef GL_TEXT_FRAGMENT_SHADER_ATI
+#define GL_TEXT_FRAGMENT_SHADER_ATI 0x8200
+#endif
 #ifndef GL_REGISTER_COMBINERS_NV
 #define GL_REGISTER_COMBINERS_NV 0x8522
 #endif
@@ -303,6 +306,8 @@
 #define YUV_CONVERSION_COMBINERS_ATI 5
 //! use a fragment program with 3D table lookup for YUV conversion
 #define YUV_CONVERSION_FRAGMENT_LOOKUP3D 6
+//! use ATI specific "text" register combiners ("fragment program")
+#define YUV_CONVERSION_TEXT_FRAGMENT 7
 //! use normal bilinear scaling for textures
 #define YUV_SCALER_BILIN 0
 //! use higher quality bicubic scaling for textures