Ejemplo n.º 1
0
/**
 * Helper routine used by the other _mesa_PixelMap() functions.
 */
static void
store_pixelmap(struct gl_context *ctx, GLenum map, GLsizei mapsize,
               const GLfloat *values)
{
    GLint i;
    struct gl_pixelmap *pm = get_pixelmap(ctx, map);
    if (!pm) {
        _mesa_error(ctx, GL_INVALID_ENUM, "glPixelMap(map)");
        return;
    }

    switch (map) {
    case GL_PIXEL_MAP_S_TO_S:
        /* special case */
        ctx->PixelMaps.StoS.Size = mapsize;
        for (i = 0; i < mapsize; i++) {
            ctx->PixelMaps.StoS.Map[i] = (GLfloat)IROUND(values[i]);
        }
        break;
    case GL_PIXEL_MAP_I_TO_I:
        /* special case */
        ctx->PixelMaps.ItoI.Size = mapsize;
        for (i = 0; i < mapsize; i++) {
            ctx->PixelMaps.ItoI.Map[i] = values[i];
        }
        break;
    default:
        /* general case */
        pm->Size = mapsize;
        for (i = 0; i < mapsize; i++) {
            GLfloat val = CLAMP(values[i], 0.0F, 1.0F);
            pm->Map[i] = val;
        }
    }
}
Ejemplo n.º 2
0
void GLAPIENTRY
_mesa_GetPixelMapfv( GLenum map, GLfloat *values )
{
   GET_CURRENT_CONTEXT(ctx);
   GLuint 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)");
      return;
   }

   mapsize = pm->Size;

   if (ctx->Pack.BufferObj->Name) {
      /* pack pixelmap into PBO */
      GLubyte *buf;
      /* Note, need to use DefaultPacking and Pack's buffer object */
      ctx->DefaultPacking.BufferObj = ctx->Pack.BufferObj;
      if (!_mesa_validate_pbo_access(1, &ctx->DefaultPacking, mapsize, 1, 1,
                                     GL_INTENSITY, GL_FLOAT, values)) {
         _mesa_error(ctx, GL_INVALID_OPERATION,
                     "glGetPixelMapfv(invalid PBO access)");
         return;
      }
      /* restore */
      ctx->DefaultPacking.BufferObj = ctx->Array.NullBufferObj;
      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,
                     "glGetPixelMapfv(PBO is mapped)");
         return;
      }
      values = (GLfloat *) ADD_POINTERS(buf, values);
   }
   else if (!values) {
      return;
   }

   if (map == GL_PIXEL_MAP_S_TO_S) {
      /* special case */
      for (i = 0; i < mapsize; i++) {
         values[i] = (GLfloat) ctx->PixelMaps.StoS.Map[i];
      }
   }
   else {
      MEMCPY(values, pm->Map, mapsize * sizeof(GLfloat));
   }

   if (ctx->Pack.BufferObj->Name) {
      ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
                              ctx->Pack.BufferObj);
   }
}
Ejemplo n.º 3
0
static void GLAPIENTRY
_mesa_GetPixelMapuiv( GLenum map, 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)");
      return;
   }

   mapsize = pm->Size;

   if (!values) {
      return;
   }

   if (map == GL_PIXEL_MAP_S_TO_S) {
      /* special case */
      memcpy(values, ctx->PixelMaps.StoS.Map, mapsize * sizeof(GLint));
   }
   else {
      for (i = 0; i < mapsize; i++) {
         values[i] = FLOAT_TO_UINT( pm->Map[i] );
      }
   }
}
Ejemplo n.º 4
0
static 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)");
        return;
    }

    mapsize = pm->Size;

    if (!validate_pbo_access(ctx, &ctx->Pack, mapsize, GL_INTENSITY,
                             GL_UNSIGNED_SHORT, bufSize, values)) {
        return;
    }

    values = (GLushort *) _mesa_map_pbo_dest(ctx, &ctx->Pack, values);
    if (!values) {
        if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
            _mesa_error(ctx, GL_INVALID_OPERATION,
                        "glGetPixelMapusv(PBO is mapped)");
        }
        return;
    }

    switch (map) {
    /* 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.);
        }
        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.);
        }
        break;
    default:
        for (i = 0; i < mapsize; i++) {
            CLAMPED_FLOAT_TO_USHORT(values[i], pm->Map[i] );
        }
    }

    _mesa_unmap_pbo_dest(ctx, &ctx->Pack);
}
Ejemplo n.º 5
0
static 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)");
        return;
    }

    mapsize = pm->Size;

    if (!validate_pbo_access(ctx, &ctx->Pack, mapsize, GL_INTENSITY,
                             GL_UNSIGNED_INT, bufSize, values)) {
        return;
    }

    values = (GLuint *) _mesa_map_pbo_dest(ctx, &ctx->Pack, values);
    if (!values) {
        if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) {
            _mesa_error(ctx, GL_INVALID_OPERATION,
                        "glGetPixelMapuiv(PBO is mapped)");
        }
        return;
    }

    if (map == GL_PIXEL_MAP_S_TO_S) {
        /* special case */
        memcpy(values, ctx->PixelMaps.StoS.Map, mapsize * sizeof(GLint));
    }
    else {
        for (i = 0; i < mapsize; i++) {
            values[i] = FLOAT_TO_UINT( pm->Map[i] );
        }
    }

    _mesa_unmap_pbo_dest(ctx, &ctx->Pack);
}
Ejemplo n.º 6
0
static void GLAPIENTRY
_mesa_GetPixelMapusv( GLenum map, 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)");
      return;
   }

   mapsize = pm->Size;

   if (!values) {
      return;
   }

   switch (map) {
   /* 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.);
      }
      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.);
      }
      break;
   default:
      for (i = 0; i < mapsize; i++) {
         CLAMPED_FLOAT_TO_USHORT(values[i], pm->Map[i] );
      }
   }
}
Ejemplo n.º 7
0
void GLAPIENTRY
_mesa_GetPixelMapusv( GLenum map, 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)");
      return;
   }
   mapsize = pm ? pm->Size : 0;

   if (ctx->Pack.BufferObj->Name) {
      /* pack pixelmap into PBO */
      GLubyte *buf;
      /* Note, need to use DefaultPacking and Pack's buffer object */
      ctx->DefaultPacking.BufferObj = ctx->Pack.BufferObj;
      if (!_mesa_validate_pbo_access(1, &ctx->DefaultPacking, mapsize, 1, 1,
                                     GL_INTENSITY, GL_UNSIGNED_SHORT,
                                     values)) {
         _mesa_error(ctx, GL_INVALID_OPERATION,
                     "glGetPixelMapusv(invalid PBO access)");
         return;
      }
      /* restore */
      ctx->DefaultPacking.BufferObj = ctx->Array.NullBufferObj;
      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,
                     "glGetPixelMapusv(PBO is mapped)");
         return;
      }
      values = (GLushort *) ADD_POINTERS(buf, values);
   }
   else if (!values) {
      return;
   }

   switch (map) {
   /* 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.);
      }
      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.);
      }
      break;
   default:
      for (i = 0; i < mapsize; i++) {
         CLAMPED_FLOAT_TO_USHORT(values[i], pm->Map[i] );
      }
   }

   if (ctx->Pack.BufferObj->Name) {
      ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
                              ctx->Pack.BufferObj);
   }
}