[Mesa-dev] [PATCH 02/21] main: Add entry point for CreateBuffers.

Laura Ekstrand laura at jlekstrand.net
Wed Jan 21 17:40:15 PST 2015


---
 src/mapi/glapi/gen/ARB_direct_state_access.xml |  7 +++
 src/mesa/main/bufferobj.c                      | 65 ++++++++++++++++++++------
 src/mesa/main/bufferobj.h                      |  5 +-
 src/mesa/main/tests/dispatch_sanity.cpp        |  1 +
 4 files changed, 64 insertions(+), 14 deletions(-)

diff --git a/src/mapi/glapi/gen/ARB_direct_state_access.xml b/src/mapi/glapi/gen/ARB_direct_state_access.xml
index 86c00f9..6c9d0e8 100644
--- a/src/mapi/glapi/gen/ARB_direct_state_access.xml
+++ b/src/mapi/glapi/gen/ARB_direct_state_access.xml
@@ -7,6 +7,13 @@
    <enum name="QUERY_TARGET"    value="0x82EA"/>
    <enum name="TEXTURE_BINDING" value="0x82EB"/>
 
+   <!-- Buffer object functions -->
+
+   <function name="CreateBuffers" offset="assign">
+      <param name="n" type="GLsizei" />
+      <param name="buffers" type="GLuint *" />
+   </function>
+
    <!-- Texture object functions -->
 
    <function name="CreateTextures" offset="assign">
diff --git a/src/mesa/main/bufferobj.c b/src/mesa/main/bufferobj.c
index aea7f1d..8653500 100644
--- a/src/mesa/main/bufferobj.c
+++ b/src/mesa/main/bufferobj.c
@@ -1283,27 +1283,29 @@ _mesa_DeleteBuffers(GLsizei n, const GLuint *ids)
 
 
 /**
- * Generate a set of unique buffer object IDs and store them in \c buffer.
- * 
- * \param n       Number of IDs to generate.
- * \param buffer  Array of \c n locations to store the IDs.
+ * This is the implementation for glGenBuffers and glCreateBuffers. It is not
+ * exposed to the rest of Mesa to encourage the use of nameless buffers in
+ * driver internals.
  */
-void GLAPIENTRY
-_mesa_GenBuffers(GLsizei n, GLuint *buffer)
+static void
+create_buffers(GLsizei n, GLuint *buffers, bool dsa)
 {
    GET_CURRENT_CONTEXT(ctx);
    GLuint first;
    GLint i;
+   struct gl_buffer_object *buf;
+
+   const char *func = dsa ? "glCreateBuffers" : "glGenBuffers";
 
    if (MESA_VERBOSE & VERBOSE_API)
-      _mesa_debug(ctx, "glGenBuffers(%d)\n", n);
+      _mesa_debug(ctx, "%s(%d)\n", func, n);
 
    if (n < 0) {
-      _mesa_error(ctx, GL_INVALID_VALUE, "glGenBuffersARB");
+      _mesa_error(ctx, GL_INVALID_VALUE, "%s(n %d < 0)", func, n);
       return;
    }
 
-   if (!buffer) {
+   if (!buffers) {
       return;
    }
 
@@ -1314,16 +1316,53 @@ _mesa_GenBuffers(GLsizei n, GLuint *buffer)
 
    first = _mesa_HashFindFreeKeyBlock(ctx->Shared->BufferObjects, n);
 
-   /* Insert the ID and pointer to dummy buffer object into hash table */
+   /* Insert the ID and pointer into the hash table. If non-DSA, insert a
+    * DummyBufferObject.  Otherwise, create a new buffer object and insert
+    * it.
+    */
    for (i = 0; i < n; i++) {
-      _mesa_HashInsert(ctx->Shared->BufferObjects, first + i,
-                       &DummyBufferObject);
-      buffer[i] = first + i;
+      buffers[i] = first + i;
+      if (dsa) {
+         ASSERT(ctx->Driver.NewBufferObject);
+         buf = ctx->Driver.NewBufferObject(ctx, buffers[i]);
+         if (!buf) {
+            _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", func);
+            return;
+         }
+      }
+      else
+         buf = &DummyBufferObject;
+
+      _mesa_HashInsert(ctx->Shared->BufferObjects, buffers[i], buf);
    }
 
    mtx_unlock(&ctx->Shared->Mutex);
 }
 
+/**
+ * Generate a set of unique buffer object IDs and store them in \c buffers.
+ *
+ * \param n        Number of IDs to generate.
+ * \param buffers  Array of \c n locations to store the IDs.
+ */
+void GLAPIENTRY
+_mesa_GenBuffers(GLsizei n, GLuint *buffers)
+{
+   create_buffers(n, buffers, false);
+}
+
+/**
+ * Create a set of buffer objects and store their unique IDs in \c buffers.
+ *
+ * \param n        Number of IDs to generate.
+ * \param buffers  Array of \c n locations to store the IDs.
+ */
+void GLAPIENTRY
+_mesa_CreateBuffers(GLsizei n, GLuint *buffers)
+{
+   create_buffers(n, buffers, true);
+}
+
 
 /**
  * Determine if ID is the name of a buffer object.
diff --git a/src/mesa/main/bufferobj.h b/src/mesa/main/bufferobj.h
index b4e1c10..665d843 100644
--- a/src/mesa/main/bufferobj.h
+++ b/src/mesa/main/bufferobj.h
@@ -150,7 +150,10 @@ void GLAPIENTRY
 _mesa_DeleteBuffers(GLsizei n, const GLuint * buffer);
 
 void GLAPIENTRY
-_mesa_GenBuffers(GLsizei n, GLuint * buffer);
+_mesa_GenBuffers(GLsizei n, GLuint *buffers);
+
+void GLAPIENTRY
+_mesa_CreateBuffers(GLsizei n, GLuint *buffers);
 
 GLboolean GLAPIENTRY
 _mesa_IsBuffer(GLuint buffer);
diff --git a/src/mesa/main/tests/dispatch_sanity.cpp b/src/mesa/main/tests/dispatch_sanity.cpp
index 39d255d..af9054a 100644
--- a/src/mesa/main/tests/dispatch_sanity.cpp
+++ b/src/mesa/main/tests/dispatch_sanity.cpp
@@ -955,6 +955,7 @@ const struct function gl_core_functions_possible[] = {
    { "glClipControl", 45, -1 },
 
    /* GL_ARB_direct_state_access */
+   { "glCreateBuffers", 45, -1 },
    { "glCreateTextures", 45, -1 },
    { "glTextureStorage1D", 45, -1 },
    { "glTextureStorage2D", 45, -1 },
-- 
2.1.0



More information about the mesa-dev mailing list