tgsi: pass zero vector to texture sampler for 1D case instead of NULL
[mesa.git] / progs / xdemos / pbutil.c
index 479abc983caa048966f0ee56d5c075f3ba57b3b8..ce133d012dc6193de7b82dc4d676065e6c3d1715 100644 (file)
@@ -9,7 +9,6 @@
  * to the GLX_SGIX_fbconfig/pbuffer extensions.
  */
 
-
 #include <stdio.h>
 #include <string.h>
 #include "pbutil.h"
  * Test if we pixel buffers are available for a particular X screen.
  * Input:  dpy - the X display
  *         screen - screen number
- * Return:  0 = pixel buffers not available.
- *          1 = pixel buffers are available via GLX 1.3.
- *          2 = pixel buffers are available via GLX_SGIX_fbconfig/pbuffer.
+ * Return:  0 = fbconfigs not available.
+ *          1 = fbconfigs are available via GLX 1.3.
+ *          2 = fbconfigs and pbuffers are available via GLX_SGIX_fbconfig
  */
 int
-QueryPbuffers(Display *dpy, int screen)
+QueryFBConfig(Display *dpy, int screen)
 {
 #if defined(GLX_VERSION_1_3)
    {
@@ -41,36 +40,55 @@ QueryPbuffers(Display *dpy, int screen)
    }
 #endif
 
-#if defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer)
    /* Try the SGIX extensions */
    {
       char *extensions;
       extensions = (char *) glXQueryServerString(dpy, screen, GLX_EXTENSIONS);
-      if (!extensions ||
-          !strstr(extensions,"GLX_SGIX_fbconfig") ||
-          !strstr(extensions,"GLX_SGIX_pbuffer")) {
-         return 0;
+      if (extensions && strstr(extensions,"GLX_SGIX_fbconfig")) {
+        return 2;
       }
-      return 2;
    }
-#endif
 
    return 0;
 }
 
+/**
+ * Test if we pixel buffers are available for a particular X screen.
+ * Input:  dpy - the X display
+ *         screen - screen number
+ * Return:  0 = pixel buffers not available.
+ *          1 = pixel buffers are available via GLX 1.3.
+ *          2 = pixel buffers are available via GLX_SGIX_fbconfig/pbuffer.
+ */
+int
+QueryPbuffers(Display *dpy, int screen)
+{
+   int ret;
 
+   ret = QueryFBConfig(dpy, screen);
+   if (ret == 2) {
+      char *extensions;
+      extensions = (char *) glXQueryServerString(dpy, screen, GLX_EXTENSIONS);
+      if (extensions && strstr(extensions, "GLX_SGIX_pbuffer"))
+        return 2;
+      else
+        return 0;
+   }
+   else
+      return ret;
+}
 
 FBCONFIG *
 ChooseFBConfig(Display *dpy, int screen, const int attribs[], int *nConfigs)
 {
-   int pbSupport = QueryPbuffers(dpy, screen);
+   int fbcSupport = QueryPbuffers(dpy, screen);
 #if defined(GLX_VERSION_1_3)
-   if (pbSupport == 1) {
+   if (fbcSupport == 1) {
       return glXChooseFBConfig(dpy, screen, attribs, nConfigs);
    }
 #endif
 #if defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer)
-   if (pbSupport == 2) {
+   if (fbcSupport == 2) {
       return glXChooseFBConfigSGIX(dpy, screen, (int *) attribs, nConfigs);
    }
 #endif
@@ -81,14 +99,14 @@ ChooseFBConfig(Display *dpy, int screen, const int attribs[], int *nConfigs)
 FBCONFIG *
 GetAllFBConfigs(Display *dpy, int screen, int *nConfigs)
 {
-   int pbSupport = QueryPbuffers(dpy, screen);
+   int fbcSupport = QueryFBConfig(dpy, screen);
 #if defined(GLX_VERSION_1_3)
-   if (pbSupport == 1) {
+   if (fbcSupport == 1) {
       return glXGetFBConfigs(dpy, screen, nConfigs);
    }
 #endif
 #if defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer)
-   if (pbSupport == 2) {
+   if (fbcSupport == 2) {
       /* The GLX_SGIX_fbconfig extensions says to pass NULL to get list
        * of all available configurations.
        */
@@ -102,14 +120,14 @@ GetAllFBConfigs(Display *dpy, int screen, int *nConfigs)
 XVisualInfo *
 GetVisualFromFBConfig(Display *dpy, int screen, FBCONFIG config)
 {
-   int pbSupport = QueryPbuffers(dpy, screen);
+   int fbcSupport = QueryFBConfig(dpy, screen);
 #if defined(GLX_VERSION_1_3)
-   if (pbSupport == 1) {
+   if (fbcSupport == 1) {
       return glXGetVisualFromFBConfig(dpy, config);
    }
 #endif
 #if defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer)
-   if (pbSupport == 2) {
+   if (fbcSupport == 2) {
       return glXGetVisualFromFBConfigSGIX(dpy, config);
    }
 #endif
@@ -131,11 +149,11 @@ GetFBConfigAttrib(Display *dpy, int screen,
                   int attrib
                   )
 {
-   int pbSupport = QueryPbuffers(dpy, screen);
+   int fbcSupport = QueryFBConfig(dpy, screen);
    int value = 0;
 
 #if defined(GLX_VERSION_1_3)
-   if (pbSupport == 1) {
+   if (fbcSupport == 1) {
       /* ok */
       if (glXGetFBConfigAttrib(dpy, config, attrib, &value) != 0) {
          value = 0;
@@ -146,7 +164,7 @@ GetFBConfigAttrib(Display *dpy, int screen,
 #endif
 
 #if defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer)
-   if (pbSupport == 2) {
+   if (fbcSupport == 2) {
       if (glXGetFBConfigAttribSGIX(dpy, config, attrib, &value) != 0) {
          value = 0;
       }
@@ -293,6 +311,43 @@ PrintFBConfigInfo(Display *dpy, int screen, FBCONFIG config, Bool horizFormat)
 
 
 
+GLXContext
+CreateContext(Display *dpy, int screen, FBCONFIG config)
+{
+   int fbcSupport = QueryFBConfig(dpy, screen);
+#if defined(GLX_VERSION_1_3)
+   if (fbcSupport == 1) {
+      /* GLX 1.3 */
+      GLXContext c;
+      c = glXCreateNewContext(dpy, config, GLX_RGBA_TYPE, NULL, True);
+      if (!c) {
+         /* try indirect */
+         c = glXCreateNewContext(dpy, config, GLX_RGBA_TYPE, NULL, False);
+      }
+      return c;
+   }
+#endif
+#if defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer)
+   if (fbcSupport == 2) {
+      GLXContext c;
+      c = glXCreateContextWithConfigSGIX(dpy, config, GLX_RGBA_TYPE_SGIX, NULL, True);
+      if (!c) {
+         c = glXCreateContextWithConfigSGIX(dpy, config, GLX_RGBA_TYPE_SGIX, NULL, False);
+      }
+      return c;
+   }
+#endif
+   return 0;
+}
+
+
+void
+DestroyContext(Display *dpy, GLXContext ctx)
+{
+   glXDestroyContext(dpy, ctx);
+}
+
+
 /* This is only used by CreatePbuffer() */
 static int XErrorFlag = 0;
 static int HandleXError(Display *dpy, XErrorEvent *event)
@@ -357,6 +412,7 @@ CreatePbuffer(Display *dpy, int screen, FBCONFIG config,
       pBuffer = None;
    }
 
+   XSync(dpy, False);
    /* Restore original X error handler */
    (void) XSetErrorHandler(oldHandler);