main: Added entry points for NamedRenderbufferStorage/Multisample
authorMartin Peres <martin.peres@linux.intel.com>
Fri, 13 Feb 2015 13:35:48 +0000 (15:35 +0200)
committerMartin Peres <martin.peres@linux.intel.com>
Wed, 25 Mar 2015 08:05:45 +0000 (10:05 +0200)
v2: Review from Laura Ekstrand
- get rid of a change that should not have happened in this patch
- improve the error messages
- fix alignments
- fix a capitalization in a function name in an error message

v3: Review from Laura Ekstrand
- move the test for the validity of the renderbuffer to less generic
  functions
- get rid of some changes that accidentally landed in the wrong commit
- revert some alignment fixes

v3: Review from Laura Ekstrand
- check that the lookup returns a valid renderbuffer
- cosmetic changes to some error messages

Reviewed-by: Laura Ekstrand <laura@jlekstrand.net>
Signed-off-by: Martin Peres <martin.peres@linux.intel.com>
src/mapi/glapi/gen/ARB_direct_state_access.xml
src/mesa/main/fbobject.c
src/mesa/main/fbobject.h
src/mesa/main/tests/dispatch_sanity.cpp

index d4e1f7c1b67e7076c92e69697d229714011f7145..8a092d697472aeea39ec1c7d41ba63cbfa7f71a1 100644 (file)
       <param name="renderbuffers" type="GLuint *" />
    </function>
 
+   <function name="NamedRenderbufferStorage" offset="assign">
+      <param name="renderbuffer" type="GLuint" />
+      <param name="internalformat" type="GLenum" />
+      <param name="width" type="GLsizei" />
+      <param name="height" type="GLsizei" />
+   </function>
+
+   <function name="NamedRenderbufferStorageMultisample" offset="assign">
+      <param name="renderbuffer" type="GLuint" />
+      <param name="samples" type="GLsizei" />
+      <param name="internalformat" type="GLenum" />
+      <param name="width" type="GLsizei" />
+      <param name="height" type="GLsizei" />
+   </function>
+
    <function name="GetNamedRenderbufferParameteriv" offset="assign">
       <param name="renderbuffer" type="GLuint" />
       <param name="pname" type="GLenum" />
index 377f9152995a010314aa56328322be19c22d6d92..072e1a8c8bbf5055d89c2c8201f29d0f8c77f6e1 100644 (file)
@@ -1785,40 +1785,17 @@ invalidate_rb(GLuint key, void *data, void *userData)
 
 
 /**
- * Helper function used by _mesa_RenderbufferStorage() and
- * _mesa_RenderbufferStorageMultisample().
- * samples will be NO_SAMPLES if called by _mesa_RenderbufferStorage().
+ * Helper function used by renderbuffer_storage_direct() and
+ * renderbuffer_storage_target().
+ * samples will be NO_SAMPLES if called by a non-multisample function.
  */
 static void
-renderbuffer_storage(GLenum target, GLenum internalFormat,
-                     GLsizei width, GLsizei height, GLsizei samples)
+renderbuffer_storage(struct gl_context *ctx, struct gl_renderbuffer *rb,
+                     GLenum internalFormat, GLsizei width,
+                     GLsizei height, GLsizei samples, const char *func)
 {
-   const char *func = samples == NO_SAMPLES ?
-      "glRenderbufferStorage" : "glRenderbufferStorageMultisample";
-   struct gl_renderbuffer *rb;
    GLenum baseFormat;
    GLenum sample_count_error;
-   GET_CURRENT_CONTEXT(ctx);
-
-   if (MESA_VERBOSE & VERBOSE_API) {
-      if (samples == NO_SAMPLES)
-         _mesa_debug(ctx, "%s(%s, %s, %d, %d)\n",
-                     func,
-                     _mesa_lookup_enum_by_nr(target),
-                     _mesa_lookup_enum_by_nr(internalFormat),
-                     width, height);
-      else
-         _mesa_debug(ctx, "%s(%s, %s, %d, %d, %d)\n",
-                     func,
-                     _mesa_lookup_enum_by_nr(target),
-                     _mesa_lookup_enum_by_nr(internalFormat),
-                     width, height, samples);
-   }
-
-   if (target != GL_RENDERBUFFER_EXT) {
-      _mesa_error(ctx, GL_INVALID_ENUM, "%s(target)", func);
-      return;
-   }
 
    baseFormat = _mesa_base_fbo_format(ctx, internalFormat);
    if (baseFormat == 0) {
@@ -1828,12 +1805,14 @@ renderbuffer_storage(GLenum target, GLenum internalFormat,
    }
 
    if (width < 0 || width > (GLsizei) ctx->Const.MaxRenderbufferSize) {
-      _mesa_error(ctx, GL_INVALID_VALUE, "%s(width)", func);
+      _mesa_error(ctx, GL_INVALID_VALUE, "%s(invalid width %d)", func,
+                  width);
       return;
    }
 
    if (height < 0 || height > (GLsizei) ctx->Const.MaxRenderbufferSize) {
-      _mesa_error(ctx, GL_INVALID_VALUE, "%s(height)", func);
+      _mesa_error(ctx, GL_INVALID_VALUE, "%s(invalid height %d)", func,
+                  height);
       return;
    }
 
@@ -1845,7 +1824,7 @@ renderbuffer_storage(GLenum target, GLenum internalFormat,
       /* check the sample count;
        * note: driver may choose to use more samples than what's requested
        */
-      sample_count_error = _mesa_check_sample_count(ctx, target,
+      sample_count_error = _mesa_check_sample_count(ctx, GL_RENDERBUFFER,
             internalFormat, samples);
       if (sample_count_error != GL_NO_ERROR) {
          _mesa_error(ctx, sample_count_error, "%s(samples)", func);
@@ -1853,12 +1832,6 @@ renderbuffer_storage(GLenum target, GLenum internalFormat,
       }
    }
 
-   rb = ctx->CurrentRenderbuffer;
-   if (!rb) {
-      _mesa_error(ctx, GL_INVALID_OPERATION, "%s", func);
-      return;
-   }
-
    FLUSH_VERTICES(ctx, _NEW_BUFFERS);
 
    if (rb->InternalFormat == internalFormat &&
@@ -1900,6 +1873,83 @@ renderbuffer_storage(GLenum target, GLenum internalFormat,
    }
 }
 
+/**
+ * Helper function used by _mesa_NamedRenderbufferStorage*().
+ * samples will be NO_SAMPLES if called by a non-multisample function.
+ */
+static void
+renderbuffer_storage_named(GLuint renderbuffer, GLenum internalFormat,
+                           GLsizei width, GLsizei height, GLsizei samples,
+                           const char *func)
+{
+   GET_CURRENT_CONTEXT(ctx);
+
+   if (MESA_VERBOSE & VERBOSE_API) {
+      if (samples == NO_SAMPLES)
+         _mesa_debug(ctx, "%s(%u, %s, %d, %d)\n",
+                     func, renderbuffer,
+                     _mesa_lookup_enum_by_nr(internalFormat),
+                     width, height);
+      else
+         _mesa_debug(ctx, "%s(%u, %s, %d, %d, %d)\n",
+                     func, renderbuffer,
+                     _mesa_lookup_enum_by_nr(internalFormat),
+                     width, height, samples);
+   }
+
+   struct gl_renderbuffer *rb = _mesa_lookup_renderbuffer(ctx, renderbuffer);
+   if (!rb || rb == &DummyRenderbuffer) {
+      /* ID was reserved, but no real renderbuffer object made yet */
+      _mesa_error(ctx, GL_INVALID_OPERATION, "%s(invalid renderbuffer %u)",
+                  func, renderbuffer);
+      return;
+   }
+
+   renderbuffer_storage(ctx, rb, internalFormat, width, height, samples, func);
+}
+
+/**
+ * Helper function used by _mesa_RenderbufferStorage() and
+ * _mesa_RenderbufferStorageMultisample().
+ * samples will be NO_SAMPLES if called by _mesa_RenderbufferStorage().
+ */
+static void
+renderbuffer_storage_target(GLenum target, GLenum internalFormat,
+                            GLsizei width, GLsizei height, GLsizei samples,
+                            const char *func)
+{
+   GET_CURRENT_CONTEXT(ctx);
+
+   if (MESA_VERBOSE & VERBOSE_API) {
+      if (samples == NO_SAMPLES)
+         _mesa_debug(ctx, "%s(%s, %s, %d, %d)\n",
+                     func,
+                     _mesa_lookup_enum_by_nr(target),
+                     _mesa_lookup_enum_by_nr(internalFormat),
+                     width, height);
+      else
+         _mesa_debug(ctx, "%s(%s, %s, %d, %d, %d)\n",
+                     func,
+                     _mesa_lookup_enum_by_nr(target),
+                     _mesa_lookup_enum_by_nr(internalFormat),
+                     width, height, samples);
+   }
+
+   if (target != GL_RENDERBUFFER_EXT) {
+      _mesa_error(ctx, GL_INVALID_ENUM, "%s(target)", func);
+      return;
+   }
+
+   if (!ctx->CurrentRenderbuffer) {
+      _mesa_error(ctx, GL_INVALID_OPERATION, "%s(no renderbuffer bound)",
+                  func);
+      return;
+   }
+
+   renderbuffer_storage(ctx, ctx->CurrentRenderbuffer, internalFormat, width,
+                        height, samples, func);
+}
+
 
 void GLAPIENTRY
 _mesa_EGLImageTargetRenderbufferStorageOES(GLenum target, GLeglImageOES image)
@@ -1959,7 +2009,8 @@ _mesa_RenderbufferStorage(GLenum target, GLenum internalFormat,
     * glRenderbufferStorageMultisample() with samples=0.  We pass in
     * a token value here just for error reporting purposes.
     */
-   renderbuffer_storage(target, internalFormat, width, height, NO_SAMPLES);
+   renderbuffer_storage_target(target, internalFormat, width, height,
+                               NO_SAMPLES, "glRenderbufferStorage");
 }
 
 
@@ -1968,7 +2019,8 @@ _mesa_RenderbufferStorageMultisample(GLenum target, GLsizei samples,
                                      GLenum internalFormat,
                                      GLsizei width, GLsizei height)
 {
-   renderbuffer_storage(target, internalFormat, width, height, samples);
+   renderbuffer_storage_target(target, internalFormat, width, height,
+                               samples, "glRenderbufferStorageMultisample");
 }
 
 
@@ -1989,7 +2041,30 @@ _es_RenderbufferStorageEXT(GLenum target, GLenum internalFormat,
       break;
    }
 
-   renderbuffer_storage(target, internalFormat, width, height, 0);
+   renderbuffer_storage_target(target, internalFormat, width, height, 0,
+                               "glRenderbufferStorageEXT");
+}
+
+void GLAPIENTRY
+_mesa_NamedRenderbufferStorage(GLuint renderbuffer, GLenum internalformat,
+                               GLsizei width, GLsizei height)
+{
+   /* GL_ARB_fbo says calling this function is equivalent to calling
+    * glRenderbufferStorageMultisample() with samples=0.  We pass in
+    * a token value here just for error reporting purposes.
+    */
+   renderbuffer_storage_named(renderbuffer, internalformat, width, height,
+                              NO_SAMPLES, "glNamedRenderbufferStorage");
+}
+
+void GLAPIENTRY
+_mesa_NamedRenderbufferStorageMultisample(GLuint renderbuffer, GLsizei samples,
+                                          GLenum internalformat,
+                                          GLsizei width, GLsizei height)
+{
+   renderbuffer_storage_named(renderbuffer, internalformat, width, height,
+                              samples,
+                              "glNamedRenderbufferStorageMultisample");
 }
 
 
index b92149b8741edeab09dfabd1a1ae0916da7dfdad..61aa1f50308859440cd9ec8561844cde5b1087d7 100644 (file)
@@ -130,6 +130,15 @@ extern void GLAPIENTRY
 _es_RenderbufferStorageEXT(GLenum target, GLenum internalFormat,
                           GLsizei width, GLsizei height);
 
+extern void GLAPIENTRY
+_mesa_NamedRenderbufferStorage(GLuint renderbuffer, GLenum internalformat,
+                               GLsizei width, GLsizei height);
+
+extern void GLAPIENTRY
+_mesa_NamedRenderbufferStorageMultisample(GLuint renderbuffer, GLsizei samples,
+                                          GLenum internalformat,
+                                          GLsizei width, GLsizei height);
+
 extern void GLAPIENTRY
 _mesa_EGLImageTargetRenderbufferStorageOES(GLenum target, GLeglImageOES image);
 
index bb573d4d9c60c790ad6e258774ad665315a381e2..eb83e4db2554b88e2602509059014e0d7fab11b3 100644 (file)
@@ -944,6 +944,8 @@ const struct function gl_core_functions_possible[] = {
    { "glGetNamedBufferPointerv", 45, -1 },
    { "glGetNamedBufferSubData", 45, -1 },
    { "glCreateRenderbuffers", 45, -1 },
+   { "glNamedRenderbufferStorage", 45, -1 },
+   { "glNamedRenderbufferStorageMultisample", 45, -1 },
    { "glGetNamedRenderbufferParameteriv", 45, -1 },
    { "glCreateTextures", 45, -1 },
    { "glTextureStorage1D", 45, -1 },