mesa: fix a typo in map_named_buffer_range
[mesa.git] / src / mesa / main / bufferobj.c
index 534326858bb35646d5e192cbf3e78ffb1708b9ce..71bc9312f45504608188fc72615df7e49db9e5da 100644 (file)
@@ -73,11 +73,11 @@ buffer_usage_warning(struct gl_context *ctx, GLuint *id, const char *fmt, ...)
    va_list args;
 
    va_start(args, fmt);
-   _mesa_gl_vdebug(ctx, id,
-                   MESA_DEBUG_SOURCE_API,
-                   MESA_DEBUG_TYPE_PERFORMANCE,
-                   MESA_DEBUG_SEVERITY_MEDIUM,
-                   fmt, args);
+   _mesa_gl_vdebugf(ctx, id,
+                    MESA_DEBUG_SOURCE_API,
+                    MESA_DEBUG_TYPE_PERFORMANCE,
+                    MESA_DEBUG_SEVERITY_MEDIUM,
+                    fmt, args);
    va_end(args);
 }
 
@@ -113,8 +113,13 @@ get_buffer_target(struct gl_context *ctx, GLenum target)
 
    switch (target) {
    case GL_ARRAY_BUFFER_ARB:
+      if (ctx->Array.ArrayBufferObj)
+         ctx->Array.ArrayBufferObj->UsageHistory |= USAGE_ARRAY_BUFFER;
       return &ctx->Array.ArrayBufferObj;
    case GL_ELEMENT_ARRAY_BUFFER_ARB:
+      if (ctx->Array.VAO->IndexBufferObj)
+         ctx->Array.VAO->IndexBufferObj->UsageHistory
+            |= USAGE_ELEMENT_ARRAY_BUFFER;
       return &ctx->Array.VAO->IndexBufferObj;
    case GL_PIXEL_PACK_BUFFER_EXT:
       return &ctx->Pack.BufferObj;
@@ -346,7 +351,8 @@ buffer_object_subdata_range_good(struct gl_context *ctx,
 
 /**
  * Test the format and type parameters and set the GL error code for
- * \c glClearBufferData and \c glClearBufferSubData.
+ * \c glClearBufferData, \c glClearNamedBufferData, \c glClearBufferSubData
+ * and \c glClearNamedBufferSubData.
  *
  * \param ctx             GL context.
  * \param internalformat  Format to which the data is to be converted.
@@ -356,7 +362,8 @@ buffer_object_subdata_range_good(struct gl_context *ctx,
  * \return   If internalformat, format and type are legal the mesa_format
  *           corresponding to internalformat, otherwise MESA_FORMAT_NONE.
  *
- * \sa glClearBufferData and glClearBufferSubData
+ * \sa glClearBufferData, glClearNamedBufferData, glClearBufferSubData and
+ *     glClearNamedBufferSubData.
  */
 static mesa_format
 validate_clear_buffer_format(struct gl_context *ctx,
@@ -386,14 +393,14 @@ validate_clear_buffer_format(struct gl_context *ctx,
    }
 
    if (!_mesa_is_color_format(format)) {
-      _mesa_error(ctx, GL_INVALID_ENUM,
+      _mesa_error(ctx, GL_INVALID_VALUE,
                   "%s(format is not a color format)", caller);
       return MESA_FORMAT_NONE;
    }
 
    errorFormatType = _mesa_error_check_format_and_type(ctx, format, type);
    if (errorFormatType != GL_NO_ERROR) {
-      _mesa_error(ctx, GL_INVALID_ENUM,
+      _mesa_error(ctx, GL_INVALID_VALUE,
                   "%s(invalid format or type)", caller);
       return MESA_FORMAT_NONE;
    }
@@ -1930,6 +1937,21 @@ _mesa_BufferStorage(GLenum target, GLsizeiptr size, const GLvoid *data,
                           false, false, false, "glBufferStorage");
 }
 
+void GLAPIENTRY
+_mesa_NamedBufferStorageEXT(GLuint buffer, GLsizeiptr size,
+                            const GLvoid *data, GLbitfield flags)
+{
+   GET_CURRENT_CONTEXT(ctx);
+
+   struct gl_buffer_object *bufObj = _mesa_lookup_bufferobj(ctx, buffer);
+   if (!_mesa_handle_bind_buffer_gen(ctx, buffer,
+                                     &bufObj, "glNamedBufferStorageEXT"))
+      return;
+
+   inlined_buffer_storage(GL_NONE, buffer, size, data, flags, GL_NONE, 0,
+                          true, false, false, "glNamedBufferStorageEXT");
+}
+
 
 void GLAPIENTRY
 _mesa_BufferStorageMemEXT(GLenum target, GLsizeiptr size,
@@ -2162,6 +2184,20 @@ _mesa_NamedBufferData(GLuint buffer, GLsizeiptr size, const GLvoid *data,
                      "glNamedBufferData");
 }
 
+void GLAPIENTRY
+_mesa_NamedBufferDataEXT(GLuint buffer, GLsizeiptr size, const GLvoid *data,
+                         GLenum usage)
+{
+   GET_CURRENT_CONTEXT(ctx);
+
+   struct gl_buffer_object *bufObj = _mesa_lookup_bufferobj(ctx, buffer);
+   if (!_mesa_handle_bind_buffer_gen(ctx, buffer,
+                                     &bufObj, "glNamedBufferDataEXT"))
+      return;
+
+   _mesa_buffer_data(ctx, bufObj, GL_NONE, size, data, usage,
+                     "glNamedBufferDataEXT");
+}
 
 static bool
 validate_buffer_sub_data(struct gl_context *ctx,
@@ -2290,6 +2326,23 @@ _mesa_NamedBufferSubData(GLuint buffer, GLintptr offset,
                    "glNamedBufferSubData");
 }
 
+void GLAPIENTRY
+_mesa_NamedBufferSubDataEXT(GLuint buffer, GLintptr offset,
+                            GLsizeiptr size, const GLvoid *data)
+{
+   GET_CURRENT_CONTEXT(ctx);
+
+   struct gl_buffer_object *bufObj = _mesa_lookup_bufferobj(ctx, buffer);
+   if (!_mesa_handle_bind_buffer_gen(ctx, buffer,
+                                     &bufObj, "glNamedBufferSubDataEXT"))
+      return;
+
+   if (validate_buffer_sub_data(ctx, bufObj, offset, size,
+                                "glNamedBufferSubDataEXT")) {
+      _mesa_buffer_sub_data(ctx, bufObj, offset, size, data);
+   }
+}
+
 
 void GLAPIENTRY
 _mesa_GetBufferSubData(GLenum target, GLintptr offset,
@@ -2635,7 +2688,7 @@ _mesa_UnmapBuffer(GLenum target)
 }
 
 GLboolean GLAPIENTRY
-_mesa_UnmapNamedBuffer_no_error(GLuint buffer)
+_mesa_UnmapNamedBufferEXT_no_error(GLuint buffer)
 {
    GET_CURRENT_CONTEXT(ctx);
    struct gl_buffer_object *bufObj = _mesa_lookup_bufferobj(ctx, buffer);
@@ -2644,7 +2697,7 @@ _mesa_UnmapNamedBuffer_no_error(GLuint buffer)
 }
 
 GLboolean GLAPIENTRY
-_mesa_UnmapNamedBuffer(GLuint buffer)
+_mesa_UnmapNamedBufferEXT(GLuint buffer)
 {
    GET_CURRENT_CONTEXT(ctx);
    struct gl_buffer_object *bufObj;
@@ -3224,30 +3277,49 @@ _mesa_MapNamedBufferRange_no_error(GLuint buffer, GLintptr offset,
                            "glMapNamedBufferRange");
 }
 
-void * GLAPIENTRY
-_mesa_MapNamedBufferRange(GLuint buffer, GLintptr offset, GLsizeiptr length,
-                          GLbitfield access)
+static void *
+map_named_buffer_range(GLuint buffer, GLintptr offset, GLsizeiptr length,
+                       GLbitfield access, bool dsa_ext, const char *func)
 {
    GET_CURRENT_CONTEXT(ctx);
-   struct gl_buffer_object *bufObj;
+   struct gl_buffer_object *bufObj = NULL;
 
    if (!ctx->Extensions.ARB_map_buffer_range) {
       _mesa_error(ctx, GL_INVALID_OPERATION,
-                  "glMapNamedBufferRange("
-                  "ARB_map_buffer_range not supported)");
+                  "%s(ARB_map_buffer_range not supported)", func);
       return NULL;
    }
 
-   bufObj = _mesa_lookup_bufferobj_err(ctx, buffer, "glMapNamedBufferRange");
-   if (!bufObj)
-      return NULL;
+   if (dsa_ext) {
+      bufObj = _mesa_lookup_bufferobj(ctx, buffer);
+      if (!_mesa_handle_bind_buffer_gen(ctx, buffer, &bufObj, func))
+         return NULL;
+   } else {
+      bufObj = _mesa_lookup_bufferobj_err(ctx, buffer, func);
+      if (!bufObj)
+         return NULL;
+   }
 
-   if (!validate_map_buffer_range(ctx, bufObj, offset, length, access,
-                                  "glMapNamedBufferRange"))
+   if (!validate_map_buffer_range(ctx, bufObj, offset, length, access, func))
       return NULL;
 
-   return map_buffer_range(ctx, bufObj, offset, length, access,
-                           "glMapNamedBufferRange");
+   return map_buffer_range(ctx, bufObj, offset, length, access, func);
+}
+
+void * GLAPIENTRY
+_mesa_MapNamedBufferRangeEXT(GLuint buffer, GLintptr offset, GLsizeiptr length,
+                             GLbitfield access)
+{
+   return map_named_buffer_range(buffer, offset, length, access, true,
+                                 "glMapNamedBufferRangeEXT");
+}
+
+void * GLAPIENTRY
+_mesa_MapNamedBufferRange(GLuint buffer, GLintptr offset, GLsizeiptr length,
+                          GLbitfield access)
+{
+   return map_named_buffer_range(buffer, offset, length, access, false,
+                                 "glMapNamedBufferRange");
 }
 
 /**
@@ -3353,6 +3425,29 @@ _mesa_MapNamedBuffer(GLuint buffer, GLenum access)
                            "glMapNamedBuffer");
 }
 
+void * GLAPIENTRY
+_mesa_MapNamedBufferEXT(GLuint buffer, GLenum access)
+{
+   GET_CURRENT_CONTEXT(ctx);
+
+   GLbitfield accessFlags;
+   if (!get_map_buffer_access_flags(ctx, access, &accessFlags)) {
+      _mesa_error(ctx, GL_INVALID_ENUM, "glMapNamedBufferEXT(invalid access)");
+      return NULL;
+   }
+
+   struct gl_buffer_object *bufObj = _mesa_lookup_bufferobj(ctx, buffer);
+   if (!_mesa_handle_bind_buffer_gen(ctx, buffer,
+                                     &bufObj, "glMapNamedBufferEXT"))
+      return NULL;
+
+   if (!validate_map_buffer_range(ctx, bufObj, 0, bufObj->Size, accessFlags,
+                                  "glMapNamedBufferEXT"))
+      return NULL;
+
+   return map_buffer_range(ctx, bufObj, 0, bufObj->Size, accessFlags,
+                           "glMapNamedBufferEXT");
+}
 
 static void
 flush_mapped_buffer_range(struct gl_context *ctx,