mesa: Change "BRIAN PAUL" to "THE AUTHORS" in license text.
[mesa.git] / src / mesa / main / bufferobj.c
index 5521617f1afa3637dba654ca0f014dcc2f9541ee..8f2359dec187eac94704474986ef65a1fba1fc26 100644 (file)
@@ -18,7 +18,7 @@
  * 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
+ * THE AUTHORS 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"
@@ -93,8 +92,8 @@ get_buffer_target(struct gl_context *ctx, GLenum target)
       }
       break;
    case GL_TEXTURE_BUFFER:
-      if (_mesa_is_desktop_gl(ctx)
-          && ctx->Extensions.ARB_texture_buffer_object) {
+      if (ctx->API == API_OPENGL_CORE &&
+          ctx->Extensions.ARB_texture_buffer_object) {
          return &ctx->Texture.BufferObject;
       }
       break;
@@ -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;
 }
 
 
@@ -822,7 +818,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 +838,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 +858,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 +948,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 +1008,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 +1056,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 +1086,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 +1110,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 +1272,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 +1286,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 +1299,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 +1339,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 +1352,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 +1387,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 +1408,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 +1617,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,
@@ -2160,17 +2145,12 @@ _mesa_BindBufferRange(GLenum target, GLuint index,
       return;
    }
 
-   if (size <= 0) {
-      _mesa_error(ctx, GL_INVALID_VALUE, "glBindBufferRange(size=%d)",
-                 (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;
+   if (buffer != 0) {
+      if (size <= 0) {
+         _mesa_error(ctx, GL_INVALID_VALUE, "glBindBufferRange(size=%d)",
+                     (int) size);
+         return;
+      }
    }
 
    switch (target) {