mesa/gles3: add support for GL_EXT_shader_group_vote
[mesa.git] / src / mesa / main / pixel.c
index e73c5a49a4ae9f3bb679069a73849f2a92a4c207..a5cb6d85ef57bf412c2ce0b3e8bac8b8feac348c 100644 (file)
@@ -1,6 +1,5 @@
 /*
  * Mesa 3-D graphics library
- * Version:  7.1
  *
  * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
  *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
  */
 
 
  * Pixel transfer functions (glPixelZoom, glPixelMap, glPixelTransfer)
  */
 
+#include "c99_math.h"
 #include "glheader.h"
 #include "bufferobj.h"
-#include "colormac.h"
 #include "context.h"
 #include "macros.h"
-#include "mfeatures.h"
 #include "pixel.h"
 #include "pbo.h"
 #include "mtypes.h"
-#include "main/dispatch.h"
-
-
-#if FEATURE_pixel_transfer
 
 
 /**********************************************************************/
 /*****                    glPixelZoom                             *****/
 /**********************************************************************/
 
-static void GLAPIENTRY
+void GLAPIENTRY
 _mesa_PixelZoom( GLfloat xfactor, GLfloat yfactor )
 {
    GET_CURRENT_CONTEXT(ctx);
 
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
-
    if (ctx->Pixel.ZoomX == xfactor &&
        ctx->Pixel.ZoomY == yfactor)
       return;
@@ -121,7 +114,7 @@ store_pixelmap(struct gl_context *ctx, GLenum map, GLsizei mapsize,
       /* special case */
       ctx->PixelMaps.StoS.Size = mapsize;
       for (i = 0; i < mapsize; i++) {
-         ctx->PixelMaps.StoS.Map[i] = (GLfloat)IROUND(values[i]);
+         ctx->PixelMaps.StoS.Map[i] = roundf(values[i]);
       }
       break;
    case GL_PIXEL_MAP_I_TO_I:
@@ -137,7 +130,6 @@ store_pixelmap(struct gl_context *ctx, GLenum map, GLsizei mapsize,
       for (i = 0; i < mapsize; i++) {
          GLfloat val = CLAMP(values[i], 0.0F, 1.0F);
          pm->Map[i] = val;
-         pm->Map8[i] = (GLint) (val * 255.0F);
       }
    }
 }
@@ -164,11 +156,10 @@ validate_pbo_access(struct gl_context *ctx,
 
    /* restore */
    _mesa_reference_buffer_object(ctx,
-                                 &ctx->DefaultPacking.BufferObj,
-                                 ctx->Shared->NullBufferObj);
+                                 &ctx->DefaultPacking.BufferObj, NULL);
 
    if (!ok) {
-      if (_mesa_is_bufferobj(pack->BufferObj)) {
+      if (pack->BufferObj) {
          _mesa_error(ctx, GL_INVALID_OPERATION,
                      "gl[Get]PixelMap*v(out of bounds PBO access)");
       } else {
@@ -181,11 +172,10 @@ validate_pbo_access(struct gl_context *ctx,
 }
 
 
-static void GLAPIENTRY
+void GLAPIENTRY
 _mesa_PixelMapfv( GLenum map, GLsizei mapsize, const GLfloat *values )
 {
    GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    /* XXX someday, test against ctx->Const.MaxPixelMapTableSize */
    if (mapsize < 1 || mapsize > MAX_PIXEL_MAP_TABLE) {
@@ -195,7 +185,7 @@ _mesa_PixelMapfv( GLenum map, GLsizei mapsize, const GLfloat *values )
 
    if (map >= GL_PIXEL_MAP_S_TO_S && map <= GL_PIXEL_MAP_I_TO_A) {
       /* test that mapsize is a power of two */
-      if (!_mesa_is_pow_two(mapsize)) {
+      if (!util_is_power_of_two_or_zero(mapsize)) {
         _mesa_error( ctx, GL_INVALID_VALUE, "glPixelMapfv(mapsize)" );
          return;
       }
@@ -210,7 +200,7 @@ _mesa_PixelMapfv( GLenum map, GLsizei mapsize, const GLfloat *values )
 
    values = (const GLfloat *) _mesa_map_pbo_source(ctx, &ctx->Unpack, values);
    if (!values) {
-      if (_mesa_is_bufferobj(ctx->Unpack.BufferObj)) {
+      if (ctx->Unpack.BufferObj) {
          _mesa_error(ctx, GL_INVALID_OPERATION,
                      "glPixelMapfv(PBO is mapped)");
       }
@@ -223,12 +213,11 @@ _mesa_PixelMapfv( GLenum map, GLsizei mapsize, const GLfloat *values )
 }
 
 
-static void GLAPIENTRY
+void GLAPIENTRY
 _mesa_PixelMapuiv(GLenum map, GLsizei mapsize, const GLuint *values )
 {
    GLfloat fvalues[MAX_PIXEL_MAP_TABLE];
    GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    if (mapsize < 1 || mapsize > MAX_PIXEL_MAP_TABLE) {
       _mesa_error( ctx, GL_INVALID_VALUE, "glPixelMapuiv(mapsize)" );
@@ -237,7 +226,7 @@ _mesa_PixelMapuiv(GLenum map, GLsizei mapsize, const GLuint *values )
 
    if (map >= GL_PIXEL_MAP_S_TO_S && map <= GL_PIXEL_MAP_I_TO_A) {
       /* test that mapsize is a power of two */
-      if (!_mesa_is_pow_two(mapsize)) {
+      if (!util_is_power_of_two_or_zero(mapsize)) {
         _mesa_error( ctx, GL_INVALID_VALUE, "glPixelMapuiv(mapsize)" );
          return;
       }
@@ -252,7 +241,7 @@ _mesa_PixelMapuiv(GLenum map, GLsizei mapsize, const GLuint *values )
 
    values = (const GLuint *) _mesa_map_pbo_source(ctx, &ctx->Unpack, values);
    if (!values) {
-      if (_mesa_is_bufferobj(ctx->Unpack.BufferObj)) {
+      if (ctx->Unpack.BufferObj) {
          _mesa_error(ctx, GL_INVALID_OPERATION,
                      "glPixelMapuiv(PBO is mapped)");
       }
@@ -279,12 +268,11 @@ _mesa_PixelMapuiv(GLenum map, GLsizei mapsize, const GLuint *values )
 }
 
 
-static void GLAPIENTRY
+void GLAPIENTRY
 _mesa_PixelMapusv(GLenum map, GLsizei mapsize, const GLushort *values )
 {
    GLfloat fvalues[MAX_PIXEL_MAP_TABLE];
    GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    if (mapsize < 1 || mapsize > MAX_PIXEL_MAP_TABLE) {
       _mesa_error( ctx, GL_INVALID_VALUE, "glPixelMapusv(mapsize)" );
@@ -293,8 +281,8 @@ _mesa_PixelMapusv(GLenum map, GLsizei mapsize, const GLushort *values )
 
    if (map >= GL_PIXEL_MAP_S_TO_S && map <= GL_PIXEL_MAP_I_TO_A) {
       /* test that mapsize is a power of two */
-      if (!_mesa_is_pow_two(mapsize)) {
-        _mesa_error( ctx, GL_INVALID_VALUE, "glPixelMapuiv(mapsize)" );
+      if (!util_is_power_of_two_or_zero(mapsize)) {
+        _mesa_error( ctx, GL_INVALID_VALUE, "glPixelMapusv(mapsize)" );
          return;
       }
    }
@@ -308,7 +296,7 @@ _mesa_PixelMapusv(GLenum map, GLsizei mapsize, const GLushort *values )
 
    values = (const GLushort *) _mesa_map_pbo_source(ctx, &ctx->Unpack, values);
    if (!values) {
-      if (_mesa_is_bufferobj(ctx->Unpack.BufferObj)) {
+      if (ctx->Unpack.BufferObj) {
          _mesa_error(ctx, GL_INVALID_OPERATION,
                      "glPixelMapusv(PBO is mapped)");
       }
@@ -335,15 +323,13 @@ _mesa_PixelMapusv(GLenum map, GLsizei mapsize, const GLushort *values )
 }
 
 
-static void GLAPIENTRY
+void GLAPIENTRY
 _mesa_GetnPixelMapfvARB( GLenum map, GLsizei bufSize, GLfloat *values )
 {
    GET_CURRENT_CONTEXT(ctx);
    GLint mapsize, i;
    const struct gl_pixelmap *pm;
 
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
-
    pm = get_pixelmap(ctx, map);
    if (!pm) {
       _mesa_error(ctx, GL_INVALID_ENUM, "glGetPixelMapfv(map)");
@@ -359,7 +345,7 @@ _mesa_GetnPixelMapfvARB( GLenum map, GLsizei bufSize, GLfloat *values )
 
    values = (GLfloat *) _mesa_map_pbo_dest(ctx, &ctx->Pack, values);
    if (!values) {
-      if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
+      if (ctx->Pack.BufferObj) {
          _mesa_error(ctx, GL_INVALID_OPERATION,
                      "glGetPixelMapfv(PBO is mapped)");
       }
@@ -380,21 +366,19 @@ _mesa_GetnPixelMapfvARB( GLenum map, GLsizei bufSize, GLfloat *values )
 }
 
 
-static void GLAPIENTRY
+void GLAPIENTRY
 _mesa_GetPixelMapfv( GLenum map, GLfloat *values )
 {
    _mesa_GetnPixelMapfvARB(map, INT_MAX, values);
 }
 
-static void GLAPIENTRY
+void GLAPIENTRY
 _mesa_GetnPixelMapuivARB( GLenum map, GLsizei bufSize, GLuint *values )
 {
    GET_CURRENT_CONTEXT(ctx);
    GLint mapsize, i;
    const struct gl_pixelmap *pm;
 
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
-
    pm = get_pixelmap(ctx, map);
    if (!pm) {
       _mesa_error(ctx, GL_INVALID_ENUM, "glGetPixelMapuiv(map)");
@@ -410,7 +394,7 @@ _mesa_GetnPixelMapuivARB( GLenum map, GLsizei bufSize, GLuint *values )
 
    values = (GLuint *) _mesa_map_pbo_dest(ctx, &ctx->Pack, values);
    if (!values) {
-      if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
+      if (ctx->Pack.BufferObj) {
          _mesa_error(ctx, GL_INVALID_OPERATION,
                      "glGetPixelMapuiv(PBO is mapped)");
       }
@@ -431,21 +415,19 @@ _mesa_GetnPixelMapuivARB( GLenum map, GLsizei bufSize, GLuint *values )
 }
 
 
-static void GLAPIENTRY
+void GLAPIENTRY
 _mesa_GetPixelMapuiv( GLenum map, GLuint *values )
 {
    _mesa_GetnPixelMapuivARB(map, INT_MAX, values);
 }
 
-static void GLAPIENTRY
+void GLAPIENTRY
 _mesa_GetnPixelMapusvARB( GLenum map, GLsizei bufSize, GLushort *values )
 {
    GET_CURRENT_CONTEXT(ctx);
    GLint mapsize, i;
    const struct gl_pixelmap *pm;
 
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
-
    pm = get_pixelmap(ctx, map);
    if (!pm) {
       _mesa_error(ctx, GL_INVALID_ENUM, "glGetPixelMapusv(map)");
@@ -461,7 +443,7 @@ _mesa_GetnPixelMapusvARB( GLenum map, GLsizei bufSize, GLushort *values )
 
    values = (GLushort *) _mesa_map_pbo_dest(ctx, &ctx->Pack, values);
    if (!values) {
-      if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
+      if (ctx->Pack.BufferObj) {
          _mesa_error(ctx, GL_INVALID_OPERATION,
                      "glGetPixelMapusv(PBO is mapped)");
       }
@@ -472,12 +454,12 @@ _mesa_GetnPixelMapusvARB( GLenum map, GLsizei bufSize, GLushort *values )
    /* special cases */
    case GL_PIXEL_MAP_I_TO_I:
       for (i = 0; i < mapsize; i++) {
-         values[i] = (GLushort) CLAMP(ctx->PixelMaps.ItoI.Map[i], 0.0, 65535.);
+         values[i] = (GLushort) CLAMP(ctx->PixelMaps.ItoI.Map[i], 0.0F, 65535.0F);
       }
       break;
    case GL_PIXEL_MAP_S_TO_S:
       for (i = 0; i < mapsize; i++) {
-         values[i] = (GLushort) CLAMP(ctx->PixelMaps.StoS.Map[i], 0.0, 65535.);
+         values[i] = (GLushort) CLAMP(ctx->PixelMaps.StoS.Map[i], 0.0F, 65535.0F);
       }
       break;
    default:
@@ -490,7 +472,7 @@ _mesa_GetnPixelMapusvARB( GLenum map, GLsizei bufSize, GLushort *values )
 }
 
 
-static void GLAPIENTRY
+void GLAPIENTRY
 _mesa_GetPixelMapusv( GLenum map, GLushort *values )
 {
    _mesa_GetnPixelMapusvARB(map, INT_MAX, values);
@@ -510,7 +492,6 @@ void GLAPIENTRY
 _mesa_PixelTransferf( GLenum pname, GLfloat param )
 {
    GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    switch (pname) {
       case GL_MAP_COLOR:
@@ -604,7 +585,7 @@ _mesa_PixelTransferf( GLenum pname, GLfloat param )
 }
 
 
-static void GLAPIENTRY
+void GLAPIENTRY
 _mesa_PixelTransferi( GLenum pname, GLint param )
 {
    _mesa_PixelTransferf( pname, (GLfloat) param );
@@ -616,12 +597,13 @@ _mesa_PixelTransferi( GLenum pname, GLint param )
 /*****                    State Management                        *****/
 /**********************************************************************/
 
-/*
- * Return a bitmask of IMAGE_*_BIT flags which to indicate which
- * pixel transfer operations are enabled.
+
+/**
+ * Update mesa pixel transfer derived state to indicate which operations are
+ * enabled.
  */
-static void
-update_image_transfer_state(struct gl_context *ctx)
+void
+_mesa_update_pixel( struct gl_context *ctx )
 {
    GLuint mask = 0;
 
@@ -641,39 +623,6 @@ update_image_transfer_state(struct gl_context *ctx)
 }
 
 
-/**
- * Update mesa pixel transfer derived state.
- */
-void _mesa_update_pixel( struct gl_context *ctx, GLuint new_state )
-{
-   if (new_state & _NEW_PIXEL)
-      update_image_transfer_state(ctx);
-}
-
-
-void
-_mesa_init_pixel_dispatch(struct _glapi_table *disp)
-{
-   SET_GetPixelMapfv(disp, _mesa_GetPixelMapfv);
-   SET_GetPixelMapuiv(disp, _mesa_GetPixelMapuiv);
-   SET_GetPixelMapusv(disp, _mesa_GetPixelMapusv);
-   SET_PixelMapfv(disp, _mesa_PixelMapfv);
-   SET_PixelMapuiv(disp, _mesa_PixelMapuiv);
-   SET_PixelMapusv(disp, _mesa_PixelMapusv);
-   SET_PixelTransferf(disp, _mesa_PixelTransferf);
-   SET_PixelTransferi(disp, _mesa_PixelTransferi);
-   SET_PixelZoom(disp, _mesa_PixelZoom);
-
-   /* GL_ARB_robustness */
-   SET_GetnPixelMapfvARB(disp, _mesa_GetnPixelMapfvARB);
-   SET_GetnPixelMapuivARB(disp, _mesa_GetnPixelMapuivARB);
-   SET_GetnPixelMapusvARB(disp, _mesa_GetnPixelMapusvARB);
-}
-
-
-#endif /* FEATURE_pixel_transfer */
-
-
 /**********************************************************************/
 /*****                      Initialization                        *****/
 /**********************************************************************/
@@ -683,7 +632,6 @@ init_pixelmap(struct gl_pixelmap *map)
 {
    map->Size = 1;
    map->Map[0] = 0.0;
-   map->Map8[0] = 0;
 }