mesa: Move glBindBufferBase and glBindBufferRange() to bufferobj.
[mesa.git] / src / mesa / main / eval.c
index 95d6e2318793c466344775dfad787f23c0901f24..e651715f7885398df15852b0bed195fd49336f4d 100644 (file)
@@ -43,8 +43,9 @@
 #include "context.h"
 #include "eval.h"
 #include "macros.h"
+#include "mfeatures.h"
 #include "mtypes.h"
-#include "glapi/dispatch.h"
+#include "main/dispatch.h"
 
 
 #if FEATURE_evaluators
@@ -100,7 +101,7 @@ GLuint _mesa_evaluator_components( GLenum target )
  * Return pointer to the gl_1d_map struct for the named target.
  */
 static struct gl_1d_map *
-get_1d_map( GLcontext *ctx, GLenum target )
+get_1d_map( struct gl_context *ctx, GLenum target )
 {
    switch (target) {
       case GL_MAP1_VERTEX_3:
@@ -150,7 +151,7 @@ get_1d_map( GLcontext *ctx, GLenum target )
  * Return pointer to the gl_2d_map struct for the named target.
  */
 static struct gl_2d_map *
-get_2d_map( GLcontext *ctx, GLenum target )
+get_2d_map( struct gl_context *ctx, GLenum target )
 {
    switch (target) {
       case GL_MAP2_VERTEX_3:
@@ -544,7 +545,7 @@ _mesa_Map2d( GLenum target,
 
 
 static void GLAPIENTRY
-_mesa_GetMapdv( GLenum target, GLenum query, GLdouble *v )
+_mesa_GetnMapdvARB( GLenum target, GLenum query, GLsizei bufSize, GLdouble *v )
 {
    GET_CURRENT_CONTEXT(ctx);
    struct gl_1d_map *map1d;
@@ -552,6 +553,7 @@ _mesa_GetMapdv( GLenum target, GLenum query, GLdouble *v )
    GLint i, n;
    GLfloat *data;
    GLuint comps;
+   GLsizei numBytes;
 
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
@@ -576,6 +578,9 @@ _mesa_GetMapdv( GLenum target, GLenum query, GLdouble *v )
             n = map2d->Uorder * map2d->Vorder * comps;
          }
         if (data) {
+            numBytes = n * sizeof *v;
+            if (bufSize < numBytes)
+               goto overflow;
            for (i=0;i<n;i++) {
               v[i] = data[i];
            }
@@ -583,19 +588,31 @@ _mesa_GetMapdv( GLenum target, GLenum query, GLdouble *v )
          break;
       case GL_ORDER:
          if (map1d) {
+            numBytes = 1 * sizeof *v;
+            if (bufSize < numBytes)
+               goto overflow;
             v[0] = (GLdouble) map1d->Order;
          }
          else {
+            numBytes = 2 * sizeof *v;
+            if (bufSize < numBytes)
+               goto overflow;
             v[0] = (GLdouble) map2d->Uorder;
             v[1] = (GLdouble) map2d->Vorder;
          }
          break;
       case GL_DOMAIN:
          if (map1d) {
+            numBytes = 2 * sizeof *v;
+            if (bufSize < numBytes)
+              goto overflow;
             v[0] = (GLdouble) map1d->u1;
             v[1] = (GLdouble) map1d->u2;
          }
          else {
+            numBytes = 4 * sizeof *v;
+            if (bufSize < numBytes)
+               goto overflow;
             v[0] = (GLdouble) map2d->u1;
             v[1] = (GLdouble) map2d->u2;
             v[2] = (GLdouble) map2d->v1;
@@ -605,11 +622,22 @@ _mesa_GetMapdv( GLenum target, GLenum query, GLdouble *v )
       default:
          _mesa_error( ctx, GL_INVALID_ENUM, "glGetMapdv(query)" );
    }
+   return;
+
+overflow:
+   _mesa_error( ctx, GL_INVALID_OPERATION,
+               "glGetnMapdvARB(out of bounds: bufSize is %d,"
+               " but %d bytes are required)", bufSize, numBytes );
 }
 
+static void GLAPIENTRY
+_mesa_GetMapdv( GLenum target, GLenum query, GLdouble *v )
+{
+   _mesa_GetnMapdvARB(target, query, INT_MAX, v);
+}
 
 static void GLAPIENTRY
-_mesa_GetMapfv( GLenum target, GLenum query, GLfloat *v )
+_mesa_GetnMapfvARB( GLenum target, GLenum query, GLsizei bufSize, GLfloat *v )
 {
    GET_CURRENT_CONTEXT(ctx);
    struct gl_1d_map *map1d;
@@ -617,6 +645,7 @@ _mesa_GetMapfv( GLenum target, GLenum query, GLfloat *v )
    GLint i, n;
    GLfloat *data;
    GLuint comps;
+   GLsizei numBytes;
 
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
@@ -641,6 +670,9 @@ _mesa_GetMapfv( GLenum target, GLenum query, GLfloat *v )
             n = map2d->Uorder * map2d->Vorder * comps;
          }
         if (data) {
+            numBytes = n * sizeof *v;
+            if (bufSize < numBytes)
+               goto overflow;
            for (i=0;i<n;i++) {
               v[i] = data[i];
            }
@@ -648,19 +680,31 @@ _mesa_GetMapfv( GLenum target, GLenum query, GLfloat *v )
          break;
       case GL_ORDER:
          if (map1d) {
+            numBytes = 1 * sizeof *v;
+            if (bufSize < numBytes)
+               goto overflow;
             v[0] = (GLfloat) map1d->Order;
          }
          else {
+            numBytes = 2 * sizeof *v;
+            if (bufSize < numBytes)
+               goto overflow;
             v[0] = (GLfloat) map2d->Uorder;
             v[1] = (GLfloat) map2d->Vorder;
          }
          break;
       case GL_DOMAIN:
          if (map1d) {
+            numBytes = 2 * sizeof *v;
+            if (bufSize < numBytes)
+               goto overflow;
             v[0] = map1d->u1;
             v[1] = map1d->u2;
          }
          else {
+            numBytes = 4 * sizeof *v;
+            if (bufSize < numBytes)
+               goto overflow;
             v[0] = map2d->u1;
             v[1] = map2d->u2;
             v[2] = map2d->v1;
@@ -670,11 +714,24 @@ _mesa_GetMapfv( GLenum target, GLenum query, GLfloat *v )
       default:
          _mesa_error( ctx, GL_INVALID_ENUM, "glGetMapfv(query)" );
    }
+   return;
+
+overflow:
+   _mesa_error( ctx, GL_INVALID_OPERATION,
+               "glGetnMapfvARB(out of bounds: bufSize is %d,"
+               " but %d bytes are required)", bufSize, numBytes );
 }
 
 
 static void GLAPIENTRY
-_mesa_GetMapiv( GLenum target, GLenum query, GLint *v )
+_mesa_GetMapfv( GLenum target, GLenum query, GLfloat *v )
+{
+   _mesa_GetnMapfvARB(target, query, INT_MAX, v);
+}
+
+
+static void GLAPIENTRY
+_mesa_GetnMapivARB( GLenum target, GLenum query, GLsizei bufSize, GLint *v )
 {
    GET_CURRENT_CONTEXT(ctx);
    struct gl_1d_map *map1d;
@@ -682,6 +739,7 @@ _mesa_GetMapiv( GLenum target, GLenum query, GLint *v )
    GLuint i, n;
    GLfloat *data;
    GLuint comps;
+   GLsizei numBytes;
 
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
@@ -706,6 +764,9 @@ _mesa_GetMapiv( GLenum target, GLenum query, GLint *v )
             n = map2d->Uorder * map2d->Vorder * comps;
          }
         if (data) {
+            numBytes = n * sizeof *v;
+            if (bufSize < numBytes)
+               goto overflow;
            for (i=0;i<n;i++) {
               v[i] = IROUND(data[i]);
            }
@@ -713,19 +774,31 @@ _mesa_GetMapiv( GLenum target, GLenum query, GLint *v )
          break;
       case GL_ORDER:
          if (map1d) {
+            numBytes = 1 * sizeof *v;
+            if (bufSize < numBytes)
+               goto overflow;
             v[0] = map1d->Order;
          }
          else {
+            numBytes = 2 * sizeof *v;
+            if (bufSize < numBytes)
+               goto overflow;
             v[0] = map2d->Uorder;
             v[1] = map2d->Vorder;
          }
          break;
       case GL_DOMAIN:
          if (map1d) {
+            numBytes = 2 * sizeof *v;
+            if (bufSize < numBytes)
+               goto overflow;
             v[0] = IROUND(map1d->u1);
             v[1] = IROUND(map1d->u2);
          }
          else {
+            numBytes = 4 * sizeof *v;
+            if (bufSize < numBytes)
+               goto overflow;
             v[0] = IROUND(map2d->u1);
             v[1] = IROUND(map2d->u2);
             v[2] = IROUND(map2d->v1);
@@ -735,9 +808,21 @@ _mesa_GetMapiv( GLenum target, GLenum query, GLint *v )
       default:
          _mesa_error( ctx, GL_INVALID_ENUM, "glGetMapiv(query)" );
    }
+   return;
+
+overflow:
+   _mesa_error( ctx, GL_INVALID_OPERATION,
+               "glGetnMapivARB(out of bounds: bufSize is %d,"
+               " but %d bytes are required)", bufSize, numBytes );
 }
 
 
+static void GLAPIENTRY
+_mesa_GetMapiv( GLenum target, GLenum query, GLint *v )
+{
+   _mesa_GetnMapivARB(target, query, INT_MAX, v);
+}
+
 
 static void GLAPIENTRY
 _mesa_MapGrid1f( GLint un, GLfloat u1, GLfloat u2 )
@@ -831,6 +916,11 @@ _mesa_init_eval_dispatch(struct _glapi_table *disp)
    SET_MapGrid1f(disp, _mesa_MapGrid1f);
    SET_MapGrid2d(disp, _mesa_MapGrid2d);
    SET_MapGrid2f(disp, _mesa_MapGrid2f);
+
+   /* GL_ARB_robustness */
+   SET_GetnMapdvARB(disp, _mesa_GetnMapdvARB);
+   SET_GetnMapfvARB(disp, _mesa_GetnMapfvARB);
+   SET_GetnMapivARB(disp, _mesa_GetnMapivARB);
 }
 
 
@@ -880,7 +970,7 @@ init_2d_map( struct gl_2d_map *map, int n, const float *initial )
 }
 
 
-void _mesa_init_eval( GLcontext *ctx )
+void _mesa_init_eval( struct gl_context *ctx )
 {
    int i;
 
@@ -894,7 +984,7 @@ void _mesa_init_eval( GLcontext *ctx )
    ctx->Eval.Map1TextureCoord4 = GL_FALSE;
    ctx->Eval.Map1Vertex3 = GL_FALSE;
    ctx->Eval.Map1Vertex4 = GL_FALSE;
-   MEMSET(ctx->Eval.Map1Attrib, 0, sizeof(ctx->Eval.Map1Attrib));
+   memset(ctx->Eval.Map1Attrib, 0, sizeof(ctx->Eval.Map1Attrib));
    ctx->Eval.Map2Color4 = GL_FALSE;
    ctx->Eval.Map2Index = GL_FALSE;
    ctx->Eval.Map2Normal = GL_FALSE;
@@ -904,7 +994,7 @@ void _mesa_init_eval( GLcontext *ctx )
    ctx->Eval.Map2TextureCoord4 = GL_FALSE;
    ctx->Eval.Map2Vertex3 = GL_FALSE;
    ctx->Eval.Map2Vertex4 = GL_FALSE;
-   MEMSET(ctx->Eval.Map2Attrib, 0, sizeof(ctx->Eval.Map2Attrib));
+   memset(ctx->Eval.Map2Attrib, 0, sizeof(ctx->Eval.Map2Attrib));
    ctx->Eval.AutoNormal = GL_FALSE;
    ctx->Eval.MapGrid1un = 1;
    ctx->Eval.MapGrid1u1 = 0.0;
@@ -952,7 +1042,7 @@ void _mesa_init_eval( GLcontext *ctx )
 }
 
 
-void _mesa_free_eval_data( GLcontext *ctx )
+void _mesa_free_eval_data( struct gl_context *ctx )
 {
    int i;