st/mesa: use fragment shader to copy stencil buffer
[mesa.git] / src / mesa / main / bufferobj.c
index 222b91eb6c1dbdd73e1c8f20e25729964be4f944..db5fdaf6075e99cb617d08ccac42a3e616436883 100644 (file)
@@ -36,7 +36,6 @@
 #include "glheader.h"
 #include "enums.h"
 #include "hash.h"
-#include "util/imports.h"
 #include "context.h"
 #include "bufferobj.h"
 #include "externalobjects.h"
@@ -47,6 +46,7 @@
 #include "transformfeedback.h"
 #include "varray.h"
 #include "util/u_atomic.h"
+#include "util/u_memory.h"
 
 
 /* Debug flags */
@@ -482,7 +482,7 @@ _mesa_delete_buffer_object(struct gl_context *ctx,
    (void) ctx;
 
    vbo_delete_minmax_cache(bufObj);
-   _mesa_align_free(bufObj->Data);
+   align_free(bufObj->Data);
 
    /* assign strange values here to help w/ debugging */
    bufObj->RefCount = -1000;
@@ -622,9 +622,9 @@ buffer_data_fallback(struct gl_context *ctx, GLenum target, GLsizeiptrARB size,
 
    (void) target;
 
-   _mesa_align_free( bufObj->Data );
+   align_free( bufObj->Data );
 
-   new_data = _mesa_align_malloc( size, ctx->Const.MinMapBufferAlignment );
+   new_data = align_malloc( size, ctx->Const.MinMapBufferAlignment );
    if (new_data) {
       bufObj->Data = (GLubyte *) new_data;
       bufObj->Size = size;
@@ -1148,7 +1148,7 @@ unbind(struct gl_context *ctx,
    if (vao->BufferBinding[index].BufferObj == obj) {
       _mesa_bind_vertex_buffer(ctx, vao, index, NULL,
                                vao->BufferBinding[index].Offset,
-                               vao->BufferBinding[index].Stride);
+                               vao->BufferBinding[index].Stride, true, false);
    }
 }
 
@@ -1228,6 +1228,19 @@ _mesa_BindBuffer(GLenum target, GLuint buffer)
    bind_buffer_object(ctx, bindTarget, buffer);
 }
 
+void
+_mesa_InternalBindElementBuffer(struct gl_context *ctx,
+                                struct gl_buffer_object *buf)
+{
+   struct gl_buffer_object **bindTarget =
+      get_buffer_target(ctx, GL_ELEMENT_ARRAY_BUFFER);
+
+   /* Move the buffer reference from the parameter to the bind point. */
+   _mesa_reference_buffer_object(ctx, bindTarget, NULL);
+   if (buf)
+      *bindTarget = buf;
+}
+
 /**
  * Binds a buffer object to a binding point.
  *
@@ -3159,6 +3172,47 @@ _mesa_CopyNamedBufferSubData(GLuint readBuffer, GLuint writeBuffer,
                         "glCopyNamedBufferSubData");
 }
 
+void GLAPIENTRY
+_mesa_InternalBufferSubDataCopyMESA(GLintptr srcBuffer, GLuint srcOffset,
+                                    GLuint dstTargetOrName, GLintptr dstOffset,
+                                    GLsizeiptr size, GLboolean named,
+                                    GLboolean ext_dsa)
+{
+   GET_CURRENT_CONTEXT(ctx);
+   struct gl_buffer_object *src = (struct gl_buffer_object *)srcBuffer;
+   struct gl_buffer_object *dst;
+   const char *func;
+
+   /* Handle behavior for all 3 variants. */
+   if (named && ext_dsa) {
+      func = "glNamedBufferSubDataEXT";
+      dst = _mesa_lookup_bufferobj(ctx, dstTargetOrName);
+      if (!_mesa_handle_bind_buffer_gen(ctx, dstTargetOrName, &dst, func))
+         goto done;
+   } else if (named) {
+      func = "glNamedBufferSubData";
+      dst = _mesa_lookup_bufferobj_err(ctx, dstTargetOrName, func);
+      if (!dst)
+         goto done;
+   } else {
+      assert(!ext_dsa);
+      func = "glBufferSubData";
+      dst = get_buffer(ctx, func, dstTargetOrName, GL_INVALID_OPERATION);
+      if (!dst)
+         goto done;
+   }
+
+   if (!validate_buffer_sub_data(ctx, dst, dstOffset, size, func))
+      goto done; /* the error is already set */
+
+   dst->MinMaxCacheDirty = true;
+   ctx->Driver.CopyBufferSubData(ctx, src, dst, srcOffset, dstOffset, size);
+
+done:
+   /* The caller passes the reference to this function, so unreference it. */
+   _mesa_reference_buffer_object(ctx, &src, NULL);
+}
+
 static bool
 validate_map_buffer_range(struct gl_context *ctx,
                           struct gl_buffer_object *bufObj, GLintptr offset,