mesa: simplify query code with get_query_binding_point()
[mesa.git] / src / mesa / main / histogram.c
index 5fee4fd0e34520219d6989b5d9daf1fc07a87b33..3a65bb19260d4a44dffb008b764fa655ed558979 100644 (file)
 #include "context.h"
 #include "image.h"
 #include "histogram.h"
+#include "main/dispatch.h"
 
 
+#if FEATURE_histogram
+
 
 /*
  * XXX the packed pixel formats haven't been tested.
@@ -186,16 +189,17 @@ pack_histogram( GLcontext *ctx,
          {
             /* temporarily store as GLuints */
             GLuint temp[4*HISTOGRAM_TABLE_SIZE];
-            GLhalfARB *dst = (GLhalfARB *) destination;
+            GLuint *dst = temp;
+            GLhalfARB *half = (GLhalfARB *) destination;
             GLuint i;
             /* get GLuint values */
             PACK_MACRO(GLuint);
             /* convert to GLhalf */
             for (i = 0; i < n * comps; i++) {
-               dst[i] = _mesa_float_to_half((GLfloat) temp[i]);
+               half[i] = _mesa_float_to_half((GLfloat) temp[i]);
             }
             if (packing->SwapBytes) {
-               _mesa_swap2((GLushort *) dst, n * comps);
+               _mesa_swap2((GLushort *) half, n * comps);
             }
          }
          break;
@@ -614,7 +618,11 @@ base_histogram_format( GLenum format )
  */
 
 
-void GLAPIENTRY
+/* this is defined below */
+static void GLAPIENTRY _mesa_ResetMinmax(GLenum target);
+
+
+static void GLAPIENTRY
 _mesa_GetMinmax(GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values)
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -649,29 +657,11 @@ _mesa_GetMinmax(GLenum target, GLboolean reset, GLenum format, GLenum type, GLvo
       return;
    }
 
-   if (ctx->Pack.BufferObj->Name) {
-      /* pack min/max values into a PBO */
-      GLubyte *buf;
-      if (!_mesa_validate_pbo_access(1, &ctx->Pack, 2, 1, 1,
-                                     format, type, values)) {
-         _mesa_error(ctx, GL_INVALID_OPERATION,
-                     "glGetMinMax(invalid PBO access)");
-         return;
-      }
-      buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
-                                              GL_WRITE_ONLY_ARB,
-                                              ctx->Pack.BufferObj);
-      if (!buf) {
-         /* buffer is already mapped - that's an error */
-         _mesa_error(ctx, GL_INVALID_OPERATION,"glGetMinMax(PBO is mapped)");
-         return;
-      }
-      values = ADD_POINTERS(buf, values);
-   }
-   else if (!values) {
-      /* not an error */
+
+   values = _mesa_map_validate_pbo_dest(ctx, 1, &ctx->Pack, 2, 1, 1,
+                                        format, type, values, "glGetMinmax");
+   if (!values)
       return;
-   }
 
    {
       GLfloat minmax[2][4];
@@ -687,10 +677,7 @@ _mesa_GetMinmax(GLenum target, GLboolean reset, GLenum format, GLenum type, GLvo
                                  format, type, values, &ctx->Pack, 0x0);
    }
 
-   if (ctx->Pack.BufferObj->Name) {
-      ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
-                              ctx->Pack.BufferObj);
-   }
+   _mesa_unmap_pbo_dest(ctx, &ctx->Pack);
 
    if (reset) {
       _mesa_ResetMinmax(GL_MINMAX);
@@ -698,7 +685,7 @@ _mesa_GetMinmax(GLenum target, GLboolean reset, GLenum format, GLenum type, GLvo
 }
 
 
-void GLAPIENTRY
+static void GLAPIENTRY
 _mesa_GetHistogram(GLenum target, GLboolean reset, GLenum format, GLenum type, GLvoid *values)
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -733,38 +720,18 @@ _mesa_GetHistogram(GLenum target, GLboolean reset, GLenum format, GLenum type, G
       return;
    }
 
-   if (ctx->Pack.BufferObj->Name) {
-      /* pack min/max values into a PBO */
-      GLubyte *buf;
-      if (!_mesa_validate_pbo_access(1, &ctx->Pack, ctx->Histogram.Width, 1, 1,
-                                     format, type, values)) {
-         _mesa_error(ctx, GL_INVALID_OPERATION,
-                     "glGetHistogram(invalid PBO access)");
-         return;
-      }
-      buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
-                                              GL_WRITE_ONLY_ARB,
-                                              ctx->Pack.BufferObj);
-      if (!buf) {
-         /* buffer is already mapped - that's an error */
-         _mesa_error(ctx,GL_INVALID_OPERATION,"glGetHistogram(PBO is mapped)");
-         return;
-      }
-      values = ADD_POINTERS(buf, values);
-   }
-   else if (!values) {
-      /* not an error */
+   values = _mesa_map_validate_pbo_dest(ctx, 1, &ctx->Pack,
+                                        ctx->Histogram.Width, 1, 1,
+                                        format, type, values,
+                                        "glGetHistogram");
+   if (!values)
       return;
-   }
 
    pack_histogram(ctx, ctx->Histogram.Width,
                   (CONST GLuint (*)[4]) ctx->Histogram.Count,
                   format, type, values, &ctx->Pack);
 
-   if (ctx->Pack.BufferObj->Name) {
-      ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
-                              ctx->Pack.BufferObj);
-   }
+   _mesa_unmap_pbo_dest(ctx, &ctx->Pack);
 
    if (reset) {
       GLuint i;
@@ -778,7 +745,7 @@ _mesa_GetHistogram(GLenum target, GLboolean reset, GLenum format, GLenum type, G
 }
 
 
-void GLAPIENTRY
+static void GLAPIENTRY
 _mesa_GetHistogramParameterfv(GLenum target, GLenum pname, GLfloat *params)
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -825,7 +792,7 @@ _mesa_GetHistogramParameterfv(GLenum target, GLenum pname, GLfloat *params)
 }
 
 
-void GLAPIENTRY
+static void GLAPIENTRY
 _mesa_GetHistogramParameteriv(GLenum target, GLenum pname, GLint *params)
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -872,7 +839,7 @@ _mesa_GetHistogramParameteriv(GLenum target, GLenum pname, GLint *params)
 }
 
 
-void GLAPIENTRY
+static void GLAPIENTRY
 _mesa_GetMinmaxParameterfv(GLenum target, GLenum pname, GLfloat *params)
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -898,7 +865,7 @@ _mesa_GetMinmaxParameterfv(GLenum target, GLenum pname, GLfloat *params)
 }
 
 
-void GLAPIENTRY
+static void GLAPIENTRY
 _mesa_GetMinmaxParameteriv(GLenum target, GLenum pname, GLint *params)
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -924,7 +891,7 @@ _mesa_GetMinmaxParameteriv(GLenum target, GLenum pname, GLint *params)
 }
 
 
-void GLAPIENTRY
+static void GLAPIENTRY
 _mesa_Histogram(GLenum target, GLsizei width, GLenum internalFormat, GLboolean sink)
 {
    GLuint i;
@@ -1007,7 +974,7 @@ _mesa_Histogram(GLenum target, GLsizei width, GLenum internalFormat, GLboolean s
 }
 
 
-void GLAPIENTRY
+static void GLAPIENTRY
 _mesa_Minmax(GLenum target, GLenum internalFormat, GLboolean sink)
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -1035,7 +1002,7 @@ _mesa_Minmax(GLenum target, GLenum internalFormat, GLboolean sink)
 }
 
 
-void GLAPIENTRY
+static void GLAPIENTRY
 _mesa_ResetHistogram(GLenum target)
 {
    GLuint i;
@@ -1061,7 +1028,7 @@ _mesa_ResetHistogram(GLenum target)
 }
 
 
-void GLAPIENTRY
+static void GLAPIENTRY
 _mesa_ResetMinmax(GLenum target)
 {
    GET_CURRENT_CONTEXT(ctx);
@@ -1084,6 +1051,24 @@ _mesa_ResetMinmax(GLenum target)
 }
 
 
+void
+_mesa_init_histogram_dispatch(struct _glapi_table *disp)
+{
+   SET_GetHistogram(disp, _mesa_GetHistogram);
+   SET_GetHistogramParameterfv(disp, _mesa_GetHistogramParameterfv);
+   SET_GetHistogramParameteriv(disp, _mesa_GetHistogramParameteriv);
+   SET_GetMinmax(disp, _mesa_GetMinmax);
+   SET_GetMinmaxParameterfv(disp, _mesa_GetMinmaxParameterfv);
+   SET_GetMinmaxParameteriv(disp, _mesa_GetMinmaxParameteriv);
+   SET_Histogram(disp, _mesa_Histogram);
+   SET_Minmax(disp, _mesa_Minmax);
+   SET_ResetHistogram(disp, _mesa_ResetHistogram);
+   SET_ResetMinmax(disp, _mesa_ResetMinmax);
+}
+
+
+#endif /* FEATURE_histogram */
+
 
 /**********************************************************************/
 /*****                      Initialization                        *****/