mesa: make _mesa_lookup_list() non-static
[mesa.git] / src / mesa / main / bufferobj.c
index 4a844308b05b609fdf97b5d0fabf70feced3bccf..bd71688e826865ade1ebb2a31e65744696540af1 100644 (file)
@@ -1,6 +1,5 @@
 /*
  * Mesa 3-D graphics library
- * Version:  7.6
  *
  * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
  * Copyright (C) 2009  VMware, Inc.  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.
  */
 
 
@@ -39,7 +39,6 @@
 #include "context.h"
 #include "bufferobj.h"
 #include "fbobject.h"
-#include "mfeatures.h"
 #include "mtypes.h"
 #include "texobj.h"
 #include "transformfeedback.h"
@@ -136,10 +135,24 @@ get_buffer(struct gl_context *ctx, const char *func, GLenum target)
 }
 
 
-static inline GLbitfield
-default_access_mode(const struct gl_context *ctx)
+/**
+ * Convert a GLbitfield describing the mapped buffer access flags
+ * into one of GL_READ_WRITE, GL_READ_ONLY, or GL_WRITE_ONLY.
+ */
+static GLenum
+simplified_access_mode(struct gl_context *ctx, GLbitfield access)
 {
-   /* Table 2.6 on page 31 (page 44 of the PDF) of the OpenGL 1.5 spec says:
+   const GLbitfield rwFlags = GL_MAP_READ_BIT | GL_MAP_WRITE_BIT;
+   if ((access & rwFlags) == rwFlags)
+      return GL_READ_WRITE;
+   if ((access & GL_MAP_READ_BIT) == GL_MAP_READ_BIT)
+      return GL_READ_ONLY;
+   if ((access & GL_MAP_WRITE_BIT) == GL_MAP_WRITE_BIT)
+      return GL_WRITE_ONLY;
+
+   /* Otherwise, AccessFlags is zero (the default state).
+    *
+    * Table 2.6 on page 31 (page 44 of the PDF) of the OpenGL 1.5 spec says:
     *
     * Name           Type  Initial Value  Legal Values
     * ...            ...   ...            ...
@@ -155,26 +168,9 @@ default_access_mode(const struct gl_context *ctx)
     * The difference is because GL_OES_mapbuffer only supports mapping buffers
     * write-only.
     */
-   return _mesa_is_gles(ctx)
-      ? GL_MAP_WRITE_BIT : (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT);
-}
+   assert(access == 0);
 
-
-/**
- * Convert a GLbitfield describing the mapped buffer access flags
- * into one of GL_READ_WRITE, GL_READ_ONLY, or GL_WRITE_ONLY.
- */
-static GLenum
-simplified_access_mode(GLbitfield access)
-{
-   const GLbitfield rwFlags = GL_MAP_READ_BIT | GL_MAP_WRITE_BIT;
-   if ((access & rwFlags) == rwFlags)
-      return GL_READ_WRITE;
-   if ((access & GL_MAP_READ_BIT) == GL_MAP_READ_BIT)
-      return GL_READ_ONLY;
-   if ((access & GL_MAP_WRITE_BIT) == GL_MAP_WRITE_BIT)
-      return GL_WRITE_ONLY;
-   return GL_READ_WRITE; /* this should never happen, but no big deal */
+   return _mesa_is_gles(ctx) ? GL_WRITE_ONLY : GL_READ_WRITE;
 }
 
 
@@ -354,7 +350,7 @@ _mesa_initialize_buffer_object( struct gl_context *ctx,
    obj->RefCount = 1;
    obj->Name = name;
    obj->Usage = GL_STATIC_DRAW_ARB;
-   obj->AccessFlags = default_access_mode(ctx);
+   obj->AccessFlags = 0;
 }
 
 
@@ -622,13 +618,10 @@ _mesa_init_buffer_objects( struct gl_context *ctx )
    _mesa_reference_buffer_object(ctx, &ctx->CopyWriteBuffer,
                                  ctx->Shared->NullBufferObj);
 
-   ctx->UniformBufferBindings = calloc(ctx->Const.MaxUniformBufferBindings,
-                                     sizeof(*ctx->UniformBufferBindings));
-
    _mesa_reference_buffer_object(ctx, &ctx->UniformBuffer,
                                 ctx->Shared->NullBufferObj);
 
-   for (i = 0; i < ctx->Const.MaxUniformBufferBindings; i++) {
+   for (i = 0; i < MAX_COMBINED_UNIFORM_BUFFERS; i++) {
       _mesa_reference_buffer_object(ctx,
                                    &ctx->UniformBufferBindings[i].BufferObject,
                                    ctx->Shared->NullBufferObj);
@@ -650,14 +643,11 @@ _mesa_free_buffer_objects( struct gl_context *ctx )
 
    _mesa_reference_buffer_object(ctx, &ctx->UniformBuffer, NULL);
 
-   for (i = 0; i < ctx->Const.MaxUniformBufferBindings; i++) {
+   for (i = 0; i < MAX_COMBINED_UNIFORM_BUFFERS; i++) {
       _mesa_reference_buffer_object(ctx,
                                    &ctx->UniformBufferBindings[i].BufferObject,
                                    NULL);
    }
-
-   free(ctx->UniformBufferBindings);
-   ctx->UniformBufferBindings = NULL;
 }
 
 static bool
@@ -822,7 +812,6 @@ void GLAPIENTRY
 _mesa_BindBuffer(GLenum target, GLuint buffer)
 {
    GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    if (MESA_VERBOSE & VERBOSE_API)
       _mesa_debug(ctx, "glBindBuffer(%s, %u)\n",
@@ -843,7 +832,6 @@ _mesa_DeleteBuffers(GLsizei n, const GLuint *ids)
 {
    GET_CURRENT_CONTEXT(ctx);
    GLsizei i;
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
    FLUSH_VERTICES(ctx, 0);
 
    if (n < 0) {
@@ -864,7 +852,7 @@ _mesa_DeleteBuffers(GLsizei n, const GLuint *ids)
          if (_mesa_bufferobj_mapped(bufObj)) {
             /* if mapped, unmap it now */
             ctx->Driver.UnmapBuffer(ctx, bufObj);
-            bufObj->AccessFlags = default_access_mode(ctx);
+            bufObj->AccessFlags = 0;
             bufObj->Pointer = NULL;
          }
 
@@ -954,7 +942,6 @@ _mesa_GenBuffers(GLsizei n, GLuint *buffer)
    GET_CURRENT_CONTEXT(ctx);
    GLuint first;
    GLint i;
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    if (MESA_VERBOSE & VERBOSE_API)
       _mesa_debug(ctx, "glGenBuffers(%d)\n", n);
@@ -1015,7 +1002,6 @@ _mesa_BufferData(GLenum target, GLsizeiptrARB size,
    GET_CURRENT_CONTEXT(ctx);
    struct gl_buffer_object *bufObj;
    bool valid_usage;
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    if (MESA_VERBOSE & VERBOSE_API)
       _mesa_debug(ctx, "glBufferData(%s, %ld, %p, %s)\n",
@@ -1064,7 +1050,7 @@ _mesa_BufferData(GLenum target, GLsizeiptrARB size,
    if (_mesa_bufferobj_mapped(bufObj)) {
       /* Unmap the existing buffer.  We'll replace it now.  Not an error. */
       ctx->Driver.UnmapBuffer(ctx, bufObj);
-      bufObj->AccessFlags = default_access_mode(ctx);
+      bufObj->AccessFlags = 0;
       ASSERT(bufObj->Pointer == NULL);
    }  
 
@@ -1094,7 +1080,6 @@ _mesa_BufferSubData(GLenum target, GLintptrARB offset,
 {
    GET_CURRENT_CONTEXT(ctx);
    struct gl_buffer_object *bufObj;
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    bufObj = buffer_object_subdata_range_good( ctx, target, offset, size,
                                               "glBufferSubDataARB" );
@@ -1119,7 +1104,6 @@ _mesa_GetBufferSubData(GLenum target, GLintptrARB offset,
 {
    GET_CURRENT_CONTEXT(ctx);
    struct gl_buffer_object *bufObj;
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    bufObj = buffer_object_subdata_range_good( ctx, target, offset, size,
                                               "glGetBufferSubDataARB" );
@@ -1282,7 +1266,7 @@ _mesa_UnmapBuffer(GLenum target)
 #endif
 
    status = ctx->Driver.UnmapBuffer( ctx, bufObj );
-   bufObj->AccessFlags = default_access_mode(ctx);
+   bufObj->AccessFlags = 0;
    ASSERT(bufObj->Pointer == NULL);
    ASSERT(bufObj->Offset == 0);
    ASSERT(bufObj->Length == 0);
@@ -1296,7 +1280,6 @@ _mesa_GetBufferParameteriv(GLenum target, GLenum pname, GLint *params)
 {
    GET_CURRENT_CONTEXT(ctx);
    struct gl_buffer_object *bufObj;
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    bufObj = get_buffer(ctx, "glGetBufferParameterivARB", target);
    if (!bufObj)
@@ -1310,7 +1293,7 @@ _mesa_GetBufferParameteriv(GLenum target, GLenum pname, GLint *params)
       *params = bufObj->Usage;
       return;
    case GL_BUFFER_ACCESS_ARB:
-      *params = simplified_access_mode(bufObj->AccessFlags);
+      *params = simplified_access_mode(ctx, bufObj->AccessFlags);
       return;
    case GL_BUFFER_MAPPED_ARB:
       *params = _mesa_bufferobj_mapped(bufObj);
@@ -1350,7 +1333,6 @@ _mesa_GetBufferParameteri64v(GLenum target, GLenum pname, GLint64 *params)
 {
    GET_CURRENT_CONTEXT(ctx);
    struct gl_buffer_object *bufObj;
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    bufObj = get_buffer(ctx, "glGetBufferParameteri64v", target);
    if (!bufObj)
@@ -1364,7 +1346,7 @@ _mesa_GetBufferParameteri64v(GLenum target, GLenum pname, GLint64 *params)
       *params = bufObj->Usage;
       return;
    case GL_BUFFER_ACCESS_ARB:
-      *params = simplified_access_mode(bufObj->AccessFlags);
+      *params = simplified_access_mode(ctx, bufObj->AccessFlags);
       return;
    case GL_BUFFER_ACCESS_FLAGS:
       if (!ctx->Extensions.ARB_map_buffer_range)
@@ -1399,7 +1381,6 @@ _mesa_GetBufferPointerv(GLenum target, GLenum pname, GLvoid **params)
 {
    GET_CURRENT_CONTEXT(ctx);
    struct gl_buffer_object * bufObj;
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    if (pname != GL_BUFFER_MAP_POINTER_ARB) {
       _mesa_error(ctx, GL_INVALID_ENUM, "glGetBufferPointervARB(pname)");
@@ -1421,7 +1402,6 @@ _mesa_CopyBufferSubData(GLenum readTarget, GLenum writeTarget,
 {
    GET_CURRENT_CONTEXT(ctx);
    struct gl_buffer_object *src, *dst;
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    src = get_buffer(ctx, "glCopyBufferSubData", readTarget);
    if (!src)
@@ -1631,7 +1611,6 @@ _mesa_FlushMappedBufferRange(GLenum target, GLintptr offset, GLsizeiptr length)
 {
    GET_CURRENT_CONTEXT(ctx);
    struct gl_buffer_object *bufObj;
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    if (!ctx->Extensions.ARB_map_buffer_range) {
       _mesa_error(ctx, GL_INVALID_OPERATION,
@@ -2074,7 +2053,8 @@ set_ubo_binding(struct gl_context *ctx,
       return;
    }
 
-   FLUSH_VERTICES(ctx, _NEW_BUFFER_OBJECT);
+   FLUSH_VERTICES(ctx, 0);
+   ctx->NewDriverState |= ctx->DriverFlags.NewUniformBuffer;
 
    _mesa_reference_buffer_object(ctx, &binding->BufferObject, bufObj);
    binding->Offset = offset;
@@ -2166,13 +2146,6 @@ _mesa_BindBufferRange(GLenum target, GLuint index,
                      (int) size);
          return;
       }
-
-      if (offset + size > bufObj->Size) {
-         _mesa_error(ctx, GL_INVALID_VALUE,
-                     "glBindBufferRange(offset + size %d > buffer size %d)",
-                     (int) (offset + size), (int) (bufObj->Size));
-         return;
-      }
    }
 
    switch (target) {