2006-06-12 16:26:29 +00:00
|
|
|
/*
|
|
|
|
* Mesa 3-D graphics library
|
|
|
|
*
|
2008-09-04 14:58:02 -06:00
|
|
|
* Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
|
2006-06-12 16:26:29 +00:00
|
|
|
* (C) Copyright IBM Corporation 2006
|
2009-05-21 09:56:41 -06:00
|
|
|
* Copyright (C) 2009 VMware, Inc. All Rights Reserved.
|
2006-06-12 16:26:29 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included
|
|
|
|
* in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* 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
|
2013-04-21 13:46:48 -07:00
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS 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.
|
2006-06-12 16:26:29 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \file arrayobj.c
|
2014-02-01 20:17:06 -08:00
|
|
|
*
|
2017-04-22 17:01:15 +10:00
|
|
|
* Implementation of Vertex Array Objects (VAOs), from OpenGL 3.1+ /
|
|
|
|
* the GL_ARB_vertex_array_object extension.
|
2006-06-12 16:26:29 +00:00
|
|
|
*
|
|
|
|
* \todo
|
|
|
|
* The code in this file borrows a lot from bufferobj.c. There's a certain
|
|
|
|
* amount of cruft left over from that origin that may be unnecessary.
|
|
|
|
*
|
|
|
|
* \author Ian Romanick <idr@us.ibm.com>
|
|
|
|
* \author Brian Paul
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "glheader.h"
|
|
|
|
#include "hash.h"
|
2011-04-07 12:07:32 +01:00
|
|
|
#include "image.h"
|
2006-06-12 16:26:29 +00:00
|
|
|
#include "imports.h"
|
|
|
|
#include "context.h"
|
|
|
|
#include "bufferobj.h"
|
|
|
|
#include "arrayobj.h"
|
2009-05-21 09:56:41 -06:00
|
|
|
#include "macros.h"
|
2011-01-05 23:11:54 -08:00
|
|
|
#include "mtypes.h"
|
2016-08-24 08:45:05 +02:00
|
|
|
#include "state.h"
|
2011-04-06 14:16:57 -06:00
|
|
|
#include "varray.h"
|
2010-02-24 12:01:14 +08:00
|
|
|
#include "main/dispatch.h"
|
2016-06-09 06:35:34 +02:00
|
|
|
#include "util/bitscan.h"
|
2018-02-03 15:22:33 +01:00
|
|
|
#include "util/u_atomic.h"
|
2006-06-12 16:26:29 +00:00
|
|
|
|
|
|
|
|
2018-01-27 16:07:22 +01:00
|
|
|
const GLubyte
|
|
|
|
_mesa_vao_attribute_map[ATTRIBUTE_MAP_MODE_MAX][VERT_ATTRIB_MAX] =
|
|
|
|
{
|
|
|
|
/* ATTRIBUTE_MAP_MODE_IDENTITY
|
|
|
|
*
|
|
|
|
* Grab vertex processing attribute VERT_ATTRIB_POS from
|
|
|
|
* the VAO attribute VERT_ATTRIB_POS, and grab vertex processing
|
|
|
|
* attribute VERT_ATTRIB_GENERIC0 from the VAO attribute
|
|
|
|
* VERT_ATTRIB_GENERIC0.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
VERT_ATTRIB_POS, /* VERT_ATTRIB_POS */
|
|
|
|
VERT_ATTRIB_NORMAL, /* VERT_ATTRIB_NORMAL */
|
|
|
|
VERT_ATTRIB_COLOR0, /* VERT_ATTRIB_COLOR0 */
|
|
|
|
VERT_ATTRIB_COLOR1, /* VERT_ATTRIB_COLOR1 */
|
|
|
|
VERT_ATTRIB_FOG, /* VERT_ATTRIB_FOG */
|
|
|
|
VERT_ATTRIB_COLOR_INDEX, /* VERT_ATTRIB_COLOR_INDEX */
|
|
|
|
VERT_ATTRIB_EDGEFLAG, /* VERT_ATTRIB_EDGEFLAG */
|
|
|
|
VERT_ATTRIB_TEX0, /* VERT_ATTRIB_TEX0 */
|
|
|
|
VERT_ATTRIB_TEX1, /* VERT_ATTRIB_TEX1 */
|
|
|
|
VERT_ATTRIB_TEX2, /* VERT_ATTRIB_TEX2 */
|
|
|
|
VERT_ATTRIB_TEX3, /* VERT_ATTRIB_TEX3 */
|
|
|
|
VERT_ATTRIB_TEX4, /* VERT_ATTRIB_TEX4 */
|
|
|
|
VERT_ATTRIB_TEX5, /* VERT_ATTRIB_TEX5 */
|
|
|
|
VERT_ATTRIB_TEX6, /* VERT_ATTRIB_TEX6 */
|
|
|
|
VERT_ATTRIB_TEX7, /* VERT_ATTRIB_TEX7 */
|
|
|
|
VERT_ATTRIB_POINT_SIZE, /* VERT_ATTRIB_POINT_SIZE */
|
|
|
|
VERT_ATTRIB_GENERIC0, /* VERT_ATTRIB_GENERIC0 */
|
|
|
|
VERT_ATTRIB_GENERIC1, /* VERT_ATTRIB_GENERIC1 */
|
|
|
|
VERT_ATTRIB_GENERIC2, /* VERT_ATTRIB_GENERIC2 */
|
|
|
|
VERT_ATTRIB_GENERIC3, /* VERT_ATTRIB_GENERIC3 */
|
|
|
|
VERT_ATTRIB_GENERIC4, /* VERT_ATTRIB_GENERIC4 */
|
|
|
|
VERT_ATTRIB_GENERIC5, /* VERT_ATTRIB_GENERIC5 */
|
|
|
|
VERT_ATTRIB_GENERIC6, /* VERT_ATTRIB_GENERIC6 */
|
|
|
|
VERT_ATTRIB_GENERIC7, /* VERT_ATTRIB_GENERIC7 */
|
|
|
|
VERT_ATTRIB_GENERIC8, /* VERT_ATTRIB_GENERIC8 */
|
|
|
|
VERT_ATTRIB_GENERIC9, /* VERT_ATTRIB_GENERIC9 */
|
|
|
|
VERT_ATTRIB_GENERIC10, /* VERT_ATTRIB_GENERIC10 */
|
|
|
|
VERT_ATTRIB_GENERIC11, /* VERT_ATTRIB_GENERIC11 */
|
|
|
|
VERT_ATTRIB_GENERIC12, /* VERT_ATTRIB_GENERIC12 */
|
|
|
|
VERT_ATTRIB_GENERIC13, /* VERT_ATTRIB_GENERIC13 */
|
|
|
|
VERT_ATTRIB_GENERIC14, /* VERT_ATTRIB_GENERIC14 */
|
|
|
|
VERT_ATTRIB_GENERIC15 /* VERT_ATTRIB_GENERIC15 */
|
|
|
|
},
|
|
|
|
|
|
|
|
/* ATTRIBUTE_MAP_MODE_POSITION
|
|
|
|
*
|
|
|
|
* Grab vertex processing attribute VERT_ATTRIB_POS as well as
|
|
|
|
* vertex processing attribute VERT_ATTRIB_GENERIC0 from the
|
|
|
|
* VAO attribute VERT_ATTRIB_POS.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
VERT_ATTRIB_POS, /* VERT_ATTRIB_POS */
|
|
|
|
VERT_ATTRIB_NORMAL, /* VERT_ATTRIB_NORMAL */
|
|
|
|
VERT_ATTRIB_COLOR0, /* VERT_ATTRIB_COLOR0 */
|
|
|
|
VERT_ATTRIB_COLOR1, /* VERT_ATTRIB_COLOR1 */
|
|
|
|
VERT_ATTRIB_FOG, /* VERT_ATTRIB_FOG */
|
|
|
|
VERT_ATTRIB_COLOR_INDEX, /* VERT_ATTRIB_COLOR_INDEX */
|
|
|
|
VERT_ATTRIB_EDGEFLAG, /* VERT_ATTRIB_EDGEFLAG */
|
|
|
|
VERT_ATTRIB_TEX0, /* VERT_ATTRIB_TEX0 */
|
|
|
|
VERT_ATTRIB_TEX1, /* VERT_ATTRIB_TEX1 */
|
|
|
|
VERT_ATTRIB_TEX2, /* VERT_ATTRIB_TEX2 */
|
|
|
|
VERT_ATTRIB_TEX3, /* VERT_ATTRIB_TEX3 */
|
|
|
|
VERT_ATTRIB_TEX4, /* VERT_ATTRIB_TEX4 */
|
|
|
|
VERT_ATTRIB_TEX5, /* VERT_ATTRIB_TEX5 */
|
|
|
|
VERT_ATTRIB_TEX6, /* VERT_ATTRIB_TEX6 */
|
|
|
|
VERT_ATTRIB_TEX7, /* VERT_ATTRIB_TEX7 */
|
|
|
|
VERT_ATTRIB_POINT_SIZE, /* VERT_ATTRIB_POINT_SIZE */
|
|
|
|
VERT_ATTRIB_POS, /* VERT_ATTRIB_GENERIC0 */
|
|
|
|
VERT_ATTRIB_GENERIC1, /* VERT_ATTRIB_GENERIC1 */
|
|
|
|
VERT_ATTRIB_GENERIC2, /* VERT_ATTRIB_GENERIC2 */
|
|
|
|
VERT_ATTRIB_GENERIC3, /* VERT_ATTRIB_GENERIC3 */
|
|
|
|
VERT_ATTRIB_GENERIC4, /* VERT_ATTRIB_GENERIC4 */
|
|
|
|
VERT_ATTRIB_GENERIC5, /* VERT_ATTRIB_GENERIC5 */
|
|
|
|
VERT_ATTRIB_GENERIC6, /* VERT_ATTRIB_GENERIC6 */
|
|
|
|
VERT_ATTRIB_GENERIC7, /* VERT_ATTRIB_GENERIC7 */
|
|
|
|
VERT_ATTRIB_GENERIC8, /* VERT_ATTRIB_GENERIC8 */
|
|
|
|
VERT_ATTRIB_GENERIC9, /* VERT_ATTRIB_GENERIC9 */
|
|
|
|
VERT_ATTRIB_GENERIC10, /* VERT_ATTRIB_GENERIC10 */
|
|
|
|
VERT_ATTRIB_GENERIC11, /* VERT_ATTRIB_GENERIC11 */
|
|
|
|
VERT_ATTRIB_GENERIC12, /* VERT_ATTRIB_GENERIC12 */
|
|
|
|
VERT_ATTRIB_GENERIC13, /* VERT_ATTRIB_GENERIC13 */
|
|
|
|
VERT_ATTRIB_GENERIC14, /* VERT_ATTRIB_GENERIC14 */
|
|
|
|
VERT_ATTRIB_GENERIC15 /* VERT_ATTRIB_GENERIC15 */
|
|
|
|
},
|
|
|
|
|
|
|
|
/* ATTRIBUTE_MAP_MODE_GENERIC0
|
|
|
|
*
|
|
|
|
* Grab vertex processing attribute VERT_ATTRIB_POS as well as
|
|
|
|
* vertex processing attribute VERT_ATTRIB_GENERIC0 from the
|
|
|
|
* VAO attribute VERT_ATTRIB_GENERIC0.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
VERT_ATTRIB_GENERIC0, /* VERT_ATTRIB_POS */
|
|
|
|
VERT_ATTRIB_NORMAL, /* VERT_ATTRIB_NORMAL */
|
|
|
|
VERT_ATTRIB_COLOR0, /* VERT_ATTRIB_COLOR0 */
|
|
|
|
VERT_ATTRIB_COLOR1, /* VERT_ATTRIB_COLOR1 */
|
|
|
|
VERT_ATTRIB_FOG, /* VERT_ATTRIB_FOG */
|
|
|
|
VERT_ATTRIB_COLOR_INDEX, /* VERT_ATTRIB_COLOR_INDEX */
|
|
|
|
VERT_ATTRIB_EDGEFLAG, /* VERT_ATTRIB_EDGEFLAG */
|
|
|
|
VERT_ATTRIB_TEX0, /* VERT_ATTRIB_TEX0 */
|
|
|
|
VERT_ATTRIB_TEX1, /* VERT_ATTRIB_TEX1 */
|
|
|
|
VERT_ATTRIB_TEX2, /* VERT_ATTRIB_TEX2 */
|
|
|
|
VERT_ATTRIB_TEX3, /* VERT_ATTRIB_TEX3 */
|
|
|
|
VERT_ATTRIB_TEX4, /* VERT_ATTRIB_TEX4 */
|
|
|
|
VERT_ATTRIB_TEX5, /* VERT_ATTRIB_TEX5 */
|
|
|
|
VERT_ATTRIB_TEX6, /* VERT_ATTRIB_TEX6 */
|
|
|
|
VERT_ATTRIB_TEX7, /* VERT_ATTRIB_TEX7 */
|
|
|
|
VERT_ATTRIB_POINT_SIZE, /* VERT_ATTRIB_POINT_SIZE */
|
|
|
|
VERT_ATTRIB_GENERIC0, /* VERT_ATTRIB_GENERIC0 */
|
|
|
|
VERT_ATTRIB_GENERIC1, /* VERT_ATTRIB_GENERIC1 */
|
|
|
|
VERT_ATTRIB_GENERIC2, /* VERT_ATTRIB_GENERIC2 */
|
|
|
|
VERT_ATTRIB_GENERIC3, /* VERT_ATTRIB_GENERIC3 */
|
|
|
|
VERT_ATTRIB_GENERIC4, /* VERT_ATTRIB_GENERIC4 */
|
|
|
|
VERT_ATTRIB_GENERIC5, /* VERT_ATTRIB_GENERIC5 */
|
|
|
|
VERT_ATTRIB_GENERIC6, /* VERT_ATTRIB_GENERIC6 */
|
|
|
|
VERT_ATTRIB_GENERIC7, /* VERT_ATTRIB_GENERIC7 */
|
|
|
|
VERT_ATTRIB_GENERIC8, /* VERT_ATTRIB_GENERIC8 */
|
|
|
|
VERT_ATTRIB_GENERIC9, /* VERT_ATTRIB_GENERIC9 */
|
|
|
|
VERT_ATTRIB_GENERIC10, /* VERT_ATTRIB_GENERIC10 */
|
|
|
|
VERT_ATTRIB_GENERIC11, /* VERT_ATTRIB_GENERIC11 */
|
|
|
|
VERT_ATTRIB_GENERIC12, /* VERT_ATTRIB_GENERIC12 */
|
|
|
|
VERT_ATTRIB_GENERIC13, /* VERT_ATTRIB_GENERIC13 */
|
|
|
|
VERT_ATTRIB_GENERIC14, /* VERT_ATTRIB_GENERIC14 */
|
|
|
|
VERT_ATTRIB_GENERIC15 /* VERT_ATTRIB_GENERIC15 */
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-06-12 16:26:29 +00:00
|
|
|
/**
|
|
|
|
* Look up the array object for the given ID.
|
2013-11-11 13:52:45 -07:00
|
|
|
*
|
2006-06-12 16:26:29 +00:00
|
|
|
* \returns
|
|
|
|
* Either a pointer to the array object with the specified ID or \c NULL for
|
|
|
|
* a non-existent ID. The spec defines ID 0 as being technically
|
|
|
|
* non-existent.
|
|
|
|
*/
|
|
|
|
|
2014-02-01 19:36:59 -08:00
|
|
|
struct gl_vertex_array_object *
|
2014-02-01 21:28:03 -08:00
|
|
|
_mesa_lookup_vao(struct gl_context *ctx, GLuint id)
|
2006-06-12 16:26:29 +00:00
|
|
|
{
|
2017-08-24 15:53:34 +02:00
|
|
|
if (id == 0) {
|
2009-06-19 17:58:47 -06:00
|
|
|
return NULL;
|
2017-08-24 15:53:34 +02:00
|
|
|
} else {
|
|
|
|
struct gl_vertex_array_object *vao;
|
|
|
|
|
|
|
|
if (ctx->Array.LastLookedUpVAO &&
|
|
|
|
ctx->Array.LastLookedUpVAO->Name == id) {
|
|
|
|
vao = ctx->Array.LastLookedUpVAO;
|
|
|
|
} else {
|
|
|
|
vao = (struct gl_vertex_array_object *)
|
|
|
|
_mesa_HashLookupLocked(ctx->Array.Objects, id);
|
|
|
|
|
|
|
|
_mesa_reference_vao(ctx, &ctx->Array.LastLookedUpVAO, vao);
|
|
|
|
}
|
|
|
|
|
|
|
|
return vao;
|
|
|
|
}
|
2006-06-12 16:26:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-02 18:24:36 +01:00
|
|
|
/**
|
|
|
|
* Looks up the array object for the given ID.
|
|
|
|
*
|
|
|
|
* Unlike _mesa_lookup_vao, this function generates a GL_INVALID_OPERATION
|
|
|
|
* error if the array object does not exist. It also returns the default
|
|
|
|
* array object when ctx is a compatibility profile context and id is zero.
|
|
|
|
*/
|
|
|
|
struct gl_vertex_array_object *
|
|
|
|
_mesa_lookup_vao_err(struct gl_context *ctx, GLuint id, const char *caller)
|
|
|
|
{
|
|
|
|
/* The ARB_direct_state_access specification says:
|
|
|
|
*
|
|
|
|
* "<vaobj> is [compatibility profile:
|
|
|
|
* zero, indicating the default vertex array object, or]
|
|
|
|
* the name of the vertex array object."
|
|
|
|
*/
|
|
|
|
if (id == 0) {
|
|
|
|
if (ctx->API == API_OPENGL_CORE) {
|
|
|
|
_mesa_error(ctx, GL_INVALID_OPERATION,
|
|
|
|
"%s(zero is not valid vaobj name in a core profile "
|
|
|
|
"context)", caller);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ctx->Array.DefaultVAO;
|
|
|
|
} else {
|
2015-03-02 18:25:45 +01:00
|
|
|
struct gl_vertex_array_object *vao;
|
2015-03-02 18:24:36 +01:00
|
|
|
|
2015-03-02 18:25:45 +01:00
|
|
|
if (ctx->Array.LastLookedUpVAO &&
|
|
|
|
ctx->Array.LastLookedUpVAO->Name == id) {
|
|
|
|
vao = ctx->Array.LastLookedUpVAO;
|
|
|
|
} else {
|
|
|
|
vao = (struct gl_vertex_array_object *)
|
2017-04-07 11:40:40 +10:00
|
|
|
_mesa_HashLookupLocked(ctx->Array.Objects, id);
|
2015-03-02 18:25:45 +01:00
|
|
|
|
|
|
|
/* The ARB_direct_state_access specification says:
|
|
|
|
*
|
|
|
|
* "An INVALID_OPERATION error is generated if <vaobj> is not
|
|
|
|
* [compatibility profile: zero or] the name of an existing
|
|
|
|
* vertex array object."
|
|
|
|
*/
|
|
|
|
if (!vao || !vao->EverBound) {
|
|
|
|
_mesa_error(ctx, GL_INVALID_OPERATION,
|
|
|
|
"%s(non-existent vaobj=%u)", caller, id);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
_mesa_reference_vao(ctx, &ctx->Array.LastLookedUpVAO, vao);
|
2015-03-02 18:24:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return vao;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-07 14:26:17 -06:00
|
|
|
/**
|
2013-04-09 20:54:25 +02:00
|
|
|
* For all the vertex binding points in the array object, unbind any pointers
|
2009-05-07 14:26:17 -06:00
|
|
|
* to any buffer objects (VBOs).
|
|
|
|
* This is done just prior to array object destruction.
|
|
|
|
*/
|
|
|
|
static void
|
2014-02-01 19:36:59 -08:00
|
|
|
unbind_array_object_vbos(struct gl_context *ctx, struct gl_vertex_array_object *obj)
|
2009-05-07 14:26:17 -06:00
|
|
|
{
|
|
|
|
GLuint i;
|
|
|
|
|
2016-10-19 17:58:44 -06:00
|
|
|
for (i = 0; i < ARRAY_SIZE(obj->BufferBinding); i++)
|
|
|
|
_mesa_reference_buffer_object(ctx, &obj->BufferBinding[i].BufferObj, NULL);
|
2009-05-07 14:26:17 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-12 16:26:29 +00:00
|
|
|
/**
|
2006-06-15 15:36:06 +00:00
|
|
|
* Allocate and initialize a new vertex array object.
|
2006-06-12 16:26:29 +00:00
|
|
|
*/
|
2014-02-01 19:36:59 -08:00
|
|
|
struct gl_vertex_array_object *
|
2014-02-01 20:48:51 -08:00
|
|
|
_mesa_new_vao(struct gl_context *ctx, GLuint name)
|
2006-06-12 16:26:29 +00:00
|
|
|
{
|
2014-02-01 19:36:59 -08:00
|
|
|
struct gl_vertex_array_object *obj = CALLOC_STRUCT(gl_vertex_array_object);
|
2006-06-15 15:36:06 +00:00
|
|
|
if (obj)
|
2014-02-01 20:48:51 -08:00
|
|
|
_mesa_initialize_vao(ctx, obj, name);
|
2006-06-12 16:26:29 +00:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete an array object.
|
|
|
|
*/
|
|
|
|
void
|
2014-02-01 20:48:51 -08:00
|
|
|
_mesa_delete_vao(struct gl_context *ctx, struct gl_vertex_array_object *obj)
|
2006-06-12 16:26:29 +00:00
|
|
|
{
|
2009-05-07 14:26:17 -06:00
|
|
|
unbind_array_object_vbos(ctx, obj);
|
2014-02-01 19:46:45 -08:00
|
|
|
_mesa_reference_buffer_object(ctx, &obj->IndexBufferObj, NULL);
|
2013-08-26 17:16:08 +10:00
|
|
|
free(obj->Label);
|
2010-02-19 11:58:49 -05:00
|
|
|
free(obj);
|
2006-06-12 16:26:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-07 13:52:26 -06:00
|
|
|
/**
|
2014-02-01 19:31:22 -08:00
|
|
|
* Set ptr to vao w/ reference counting.
|
2014-02-01 20:48:51 -08:00
|
|
|
* Note: this should only be called from the _mesa_reference_vao()
|
2012-06-26 14:47:19 -06:00
|
|
|
* inline function.
|
2009-05-07 13:52:26 -06:00
|
|
|
*/
|
|
|
|
void
|
2014-02-01 20:48:51 -08:00
|
|
|
_mesa_reference_vao_(struct gl_context *ctx,
|
|
|
|
struct gl_vertex_array_object **ptr,
|
|
|
|
struct gl_vertex_array_object *vao)
|
2009-05-07 13:52:26 -06:00
|
|
|
{
|
2014-02-01 19:31:22 -08:00
|
|
|
assert(*ptr != vao);
|
2009-05-07 13:52:26 -06:00
|
|
|
|
|
|
|
if (*ptr) {
|
|
|
|
/* Unreference the old array object */
|
2014-02-01 19:36:59 -08:00
|
|
|
struct gl_vertex_array_object *oldObj = *ptr;
|
2009-05-07 13:52:26 -06:00
|
|
|
|
2018-02-03 15:22:33 +01:00
|
|
|
bool deleteFlag;
|
|
|
|
if (oldObj->SharedAndImmutable) {
|
|
|
|
deleteFlag = p_atomic_dec_zero(&oldObj->RefCount);
|
|
|
|
} else {
|
|
|
|
assert(oldObj->RefCount > 0);
|
|
|
|
oldObj->RefCount--;
|
|
|
|
deleteFlag = (oldObj->RefCount == 0);
|
|
|
|
}
|
2009-05-07 13:52:26 -06:00
|
|
|
|
2018-02-03 15:22:33 +01:00
|
|
|
if (deleteFlag)
|
2015-09-27 21:28:22 +02:00
|
|
|
_mesa_delete_vao(ctx, oldObj);
|
2009-05-07 13:52:26 -06:00
|
|
|
|
|
|
|
*ptr = NULL;
|
|
|
|
}
|
2015-02-20 20:18:47 -08:00
|
|
|
assert(!*ptr);
|
2009-05-07 13:52:26 -06:00
|
|
|
|
2014-02-01 19:31:22 -08:00
|
|
|
if (vao) {
|
2009-05-07 13:52:26 -06:00
|
|
|
/* reference new array object */
|
2018-02-03 15:22:33 +01:00
|
|
|
if (vao->SharedAndImmutable) {
|
|
|
|
p_atomic_inc(&vao->RefCount);
|
|
|
|
} else {
|
|
|
|
assert(vao->RefCount > 0);
|
|
|
|
vao->RefCount++;
|
|
|
|
}
|
2017-04-21 13:29:46 +10:00
|
|
|
|
|
|
|
*ptr = vao;
|
2009-05-07 13:52:26 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-06 17:16:51 -06:00
|
|
|
/**
|
2018-01-26 11:09:44 -07:00
|
|
|
* Initialize attributes of a vertex array within a vertex array object.
|
2016-10-06 17:16:51 -06:00
|
|
|
* \param vao the container vertex array object
|
|
|
|
* \param index which array in the VAO to initialize
|
|
|
|
* \param size number of components (1, 2, 3 or 4) per attribute
|
|
|
|
* \param type datatype of the attribute (GL_FLOAT, GL_INT, etc).
|
|
|
|
*/
|
2009-01-23 11:25:13 -07:00
|
|
|
static void
|
2010-10-12 12:26:10 -04:00
|
|
|
init_array(struct gl_context *ctx,
|
2016-10-06 17:16:51 -06:00
|
|
|
struct gl_vertex_array_object *vao,
|
2018-01-30 11:02:06 -07:00
|
|
|
gl_vert_attrib index, GLint size, GLint type)
|
2009-01-23 11:25:13 -07:00
|
|
|
{
|
2018-01-29 14:09:54 -07:00
|
|
|
assert(index < ARRAY_SIZE(vao->VertexAttrib));
|
2016-10-06 17:30:20 -06:00
|
|
|
struct gl_array_attributes *array = &vao->VertexAttrib[index];
|
2018-01-29 14:09:54 -07:00
|
|
|
assert(index < ARRAY_SIZE(vao->BufferBinding));
|
2016-10-19 17:58:44 -06:00
|
|
|
struct gl_vertex_buffer_binding *binding = &vao->BufferBinding[index];
|
2013-04-09 20:54:25 +02:00
|
|
|
|
2009-01-23 11:25:13 -07:00
|
|
|
array->Size = size;
|
|
|
|
array->Type = type;
|
|
|
|
array->Format = GL_RGBA; /* only significant for GL_EXT_vertex_array_bgra */
|
|
|
|
array->Stride = 0;
|
|
|
|
array->Ptr = NULL;
|
2013-04-09 20:54:25 +02:00
|
|
|
array->RelativeOffset = 0;
|
2009-01-23 11:25:13 -07:00
|
|
|
array->Enabled = GL_FALSE;
|
|
|
|
array->Normalized = GL_FALSE;
|
2011-10-31 17:29:17 -07:00
|
|
|
array->Integer = GL_FALSE;
|
2015-02-20 11:41:01 +10:00
|
|
|
array->Doubles = GL_FALSE;
|
2011-04-07 12:07:32 +01:00
|
|
|
array->_ElementSize = size * _mesa_sizeof_type(type);
|
2018-01-29 14:09:54 -07:00
|
|
|
ASSERT_BITFIELD_SIZE(struct gl_array_attributes, BufferBindingIndex,
|
|
|
|
VERT_ATTRIB_MAX - 1);
|
2016-10-06 17:21:09 -06:00
|
|
|
array->BufferBindingIndex = index;
|
2013-04-09 20:54:25 +02:00
|
|
|
|
|
|
|
binding->Offset = 0;
|
|
|
|
binding->Stride = array->_ElementSize;
|
|
|
|
binding->BufferObj = NULL;
|
2017-11-15 23:53:04 +01:00
|
|
|
binding->_BoundArrays = BITFIELD_BIT(index);
|
2013-04-09 20:54:25 +02:00
|
|
|
|
2009-01-23 11:25:13 -07:00
|
|
|
/* Vertex array buffers */
|
2013-04-09 20:54:25 +02:00
|
|
|
_mesa_reference_buffer_object(ctx, &binding->BufferObj,
|
2009-05-07 13:30:39 -06:00
|
|
|
ctx->Shared->NullBufferObj);
|
2009-01-23 11:25:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2014-02-01 19:36:59 -08:00
|
|
|
* Initialize a gl_vertex_array_object's arrays.
|
2009-01-23 11:25:13 -07:00
|
|
|
*/
|
2006-06-12 16:26:29 +00:00
|
|
|
void
|
2014-02-01 20:48:51 -08:00
|
|
|
_mesa_initialize_vao(struct gl_context *ctx,
|
2016-10-06 17:16:51 -06:00
|
|
|
struct gl_vertex_array_object *vao,
|
2014-02-01 20:48:51 -08:00
|
|
|
GLuint name)
|
2006-06-12 16:26:29 +00:00
|
|
|
{
|
|
|
|
GLuint i;
|
|
|
|
|
2016-10-06 17:16:51 -06:00
|
|
|
vao->Name = name;
|
2006-06-12 16:26:29 +00:00
|
|
|
|
2016-10-06 17:16:51 -06:00
|
|
|
vao->RefCount = 1;
|
2018-02-03 15:22:33 +01:00
|
|
|
vao->SharedAndImmutable = false;
|
2009-05-07 13:52:26 -06:00
|
|
|
|
2009-01-23 11:25:13 -07:00
|
|
|
/* Init the individual arrays */
|
2016-10-06 17:16:51 -06:00
|
|
|
for (i = 0; i < ARRAY_SIZE(vao->VertexAttrib); i++) {
|
2011-10-31 22:23:51 +01:00
|
|
|
switch (i) {
|
|
|
|
case VERT_ATTRIB_NORMAL:
|
2016-10-06 17:16:51 -06:00
|
|
|
init_array(ctx, vao, VERT_ATTRIB_NORMAL, 3, GL_FLOAT);
|
2011-10-31 22:23:51 +01:00
|
|
|
break;
|
|
|
|
case VERT_ATTRIB_COLOR1:
|
2016-10-06 17:16:51 -06:00
|
|
|
init_array(ctx, vao, VERT_ATTRIB_COLOR1, 3, GL_FLOAT);
|
2011-10-31 22:23:51 +01:00
|
|
|
break;
|
|
|
|
case VERT_ATTRIB_FOG:
|
2016-10-06 17:16:51 -06:00
|
|
|
init_array(ctx, vao, VERT_ATTRIB_FOG, 1, GL_FLOAT);
|
2011-10-31 22:23:51 +01:00
|
|
|
break;
|
|
|
|
case VERT_ATTRIB_COLOR_INDEX:
|
2016-10-06 17:16:51 -06:00
|
|
|
init_array(ctx, vao, VERT_ATTRIB_COLOR_INDEX, 1, GL_FLOAT);
|
2011-10-31 22:23:51 +01:00
|
|
|
break;
|
|
|
|
case VERT_ATTRIB_EDGEFLAG:
|
2016-10-06 17:16:51 -06:00
|
|
|
init_array(ctx, vao, VERT_ATTRIB_EDGEFLAG, 1, GL_BOOL);
|
2011-10-31 22:23:51 +01:00
|
|
|
break;
|
|
|
|
case VERT_ATTRIB_POINT_SIZE:
|
2016-10-06 17:16:51 -06:00
|
|
|
init_array(ctx, vao, VERT_ATTRIB_POINT_SIZE, 1, GL_FLOAT);
|
2011-10-31 22:23:51 +01:00
|
|
|
break;
|
|
|
|
default:
|
2016-10-06 17:16:51 -06:00
|
|
|
init_array(ctx, vao, i, 4, GL_FLOAT);
|
2011-10-31 22:23:51 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-11-23 15:59:06 +08:00
|
|
|
|
2018-01-27 16:07:22 +01:00
|
|
|
vao->_AttributeMapMode = ATTRIBUTE_MAP_MODE_IDENTITY;
|
|
|
|
|
2016-10-06 17:16:51 -06:00
|
|
|
_mesa_reference_buffer_object(ctx, &vao->IndexBufferObj,
|
2011-11-23 15:59:06 +08:00
|
|
|
ctx->Shared->NullBufferObj);
|
2006-06-12 16:26:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-09 20:54:25 +02:00
|
|
|
/**
|
2018-01-25 09:12:59 -07:00
|
|
|
* Updates the derived gl_vertex_arrays when a gl_array_attributes
|
2013-04-09 20:54:25 +02:00
|
|
|
* or a gl_vertex_buffer_binding has changed.
|
|
|
|
*/
|
|
|
|
void
|
2018-01-26 11:35:43 -07:00
|
|
|
_mesa_update_vao_derived_arrays(struct gl_context *ctx,
|
|
|
|
struct gl_vertex_array_object *vao)
|
2013-04-09 20:54:25 +02:00
|
|
|
{
|
2018-02-03 15:22:33 +01:00
|
|
|
/* Make sure we do not run into problems with shared objects */
|
|
|
|
assert(!vao->SharedAndImmutable || vao->NewArrays == 0);
|
2013-04-09 20:54:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-03 15:22:33 +01:00
|
|
|
void
|
|
|
|
_mesa_set_vao_immutable(struct gl_context *ctx,
|
|
|
|
struct gl_vertex_array_object *vao)
|
|
|
|
{
|
|
|
|
_mesa_update_vao_derived_arrays(ctx, vao);
|
|
|
|
vao->NewArrays = 0;
|
|
|
|
vao->SharedAndImmutable = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-17 08:09:04 +02:00
|
|
|
bool
|
|
|
|
_mesa_all_varyings_in_vbos(const struct gl_vertex_array_object *vao)
|
|
|
|
{
|
|
|
|
/* Walk those enabled arrays that have the default vbo attached */
|
2017-11-15 23:53:04 +01:00
|
|
|
GLbitfield mask = vao->_Enabled & ~vao->VertexAttribBufferMask;
|
2016-06-17 08:09:04 +02:00
|
|
|
|
|
|
|
while (mask) {
|
|
|
|
/* Do not use u_bit_scan64 as we can walk multiple
|
|
|
|
* attrib arrays at once
|
|
|
|
*/
|
2017-11-15 23:53:04 +01:00
|
|
|
const int i = ffs(mask) - 1;
|
2016-10-06 17:30:20 -06:00
|
|
|
const struct gl_array_attributes *attrib_array =
|
2016-06-17 08:09:04 +02:00
|
|
|
&vao->VertexAttrib[i];
|
|
|
|
const struct gl_vertex_buffer_binding *buffer_binding =
|
2016-10-19 17:58:44 -06:00
|
|
|
&vao->BufferBinding[attrib_array->BufferBindingIndex];
|
2016-06-17 08:09:04 +02:00
|
|
|
|
|
|
|
/* Only enabled arrays shall appear in the _Enabled bitmask */
|
|
|
|
assert(attrib_array->Enabled);
|
|
|
|
/* We have already masked out vao->VertexAttribBufferMask */
|
|
|
|
assert(!_mesa_is_bufferobj(buffer_binding->BufferObj));
|
|
|
|
|
|
|
|
/* Bail out once we find the first non vbo with a non zero stride */
|
|
|
|
if (buffer_binding->Stride != 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Note that we cannot use the xor variant since the _BoundArray mask
|
|
|
|
* may contain array attributes that are bound but not enabled.
|
|
|
|
*/
|
|
|
|
mask &= ~buffer_binding->_BoundArrays;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-14 14:03:58 +02:00
|
|
|
bool
|
|
|
|
_mesa_all_buffers_are_unmapped(const struct gl_vertex_array_object *vao)
|
|
|
|
{
|
|
|
|
/* Walk the enabled arrays that have a vbo attached */
|
2017-11-15 23:53:04 +01:00
|
|
|
GLbitfield mask = vao->_Enabled & vao->VertexAttribBufferMask;
|
2016-08-14 14:03:58 +02:00
|
|
|
|
|
|
|
while (mask) {
|
2017-11-15 23:53:04 +01:00
|
|
|
const int i = ffs(mask) - 1;
|
2016-10-06 17:30:20 -06:00
|
|
|
const struct gl_array_attributes *attrib_array =
|
2016-08-14 14:03:58 +02:00
|
|
|
&vao->VertexAttrib[i];
|
|
|
|
const struct gl_vertex_buffer_binding *buffer_binding =
|
2016-10-19 17:58:44 -06:00
|
|
|
&vao->BufferBinding[attrib_array->BufferBindingIndex];
|
2016-08-14 14:03:58 +02:00
|
|
|
|
|
|
|
/* Only enabled arrays shall appear in the _Enabled bitmask */
|
|
|
|
assert(attrib_array->Enabled);
|
|
|
|
/* We have already masked with vao->VertexAttribBufferMask */
|
|
|
|
assert(_mesa_is_bufferobj(buffer_binding->BufferObj));
|
|
|
|
|
|
|
|
/* Bail out once we find the first disallowed mapping */
|
|
|
|
if (_mesa_check_disallowed_mapping(buffer_binding->BufferObj))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* We have handled everything that is bound to this buffer_binding. */
|
|
|
|
mask &= ~buffer_binding->_BoundArrays;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2016-06-17 08:09:04 +02:00
|
|
|
|
2006-06-12 16:26:29 +00:00
|
|
|
/**********************************************************************/
|
|
|
|
/* API Functions */
|
|
|
|
/**********************************************************************/
|
|
|
|
|
2009-06-19 18:07:49 -06:00
|
|
|
|
2006-06-12 16:26:29 +00:00
|
|
|
/**
|
2017-04-22 17:10:09 +10:00
|
|
|
* ARB version of glBindVertexArray()
|
2006-06-12 16:26:29 +00:00
|
|
|
*/
|
2017-07-18 18:08:47 +02:00
|
|
|
static ALWAYS_INLINE void
|
|
|
|
bind_vertex_array(struct gl_context *ctx, GLuint id, bool no_error)
|
2006-06-12 16:26:29 +00:00
|
|
|
{
|
2017-07-18 18:08:47 +02:00
|
|
|
struct gl_vertex_array_object *const oldObj = ctx->Array.VAO;
|
2014-02-01 19:36:59 -08:00
|
|
|
struct gl_vertex_array_object *newObj = NULL;
|
2006-06-12 16:26:29 +00:00
|
|
|
|
2015-02-20 20:18:47 -08:00
|
|
|
assert(oldObj != NULL);
|
2006-06-12 16:26:29 +00:00
|
|
|
|
2017-04-22 17:10:09 +10:00
|
|
|
if (oldObj->Name == id)
|
2006-06-12 16:26:29 +00:00
|
|
|
return; /* rebinding the same array object- no change */
|
|
|
|
|
|
|
|
/*
|
2009-05-07 14:26:17 -06:00
|
|
|
* Get pointer to new array object (newObj)
|
2006-06-12 16:26:29 +00:00
|
|
|
*/
|
|
|
|
if (id == 0) {
|
|
|
|
/* The spec says there is no array object named 0, but we use
|
|
|
|
* one internally because it simplifies things.
|
|
|
|
*/
|
2014-02-01 19:14:38 -08:00
|
|
|
newObj = ctx->Array.DefaultVAO;
|
2006-06-12 16:26:29 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* non-default array object */
|
2014-02-01 21:28:03 -08:00
|
|
|
newObj = _mesa_lookup_vao(ctx, id);
|
2017-07-18 18:08:47 +02:00
|
|
|
if (!no_error && !newObj) {
|
2017-04-22 17:01:15 +10:00
|
|
|
_mesa_error(ctx, GL_INVALID_OPERATION,
|
|
|
|
"glBindVertexArray(non-gen name)");
|
|
|
|
return;
|
2012-01-31 09:00:48 -07:00
|
|
|
}
|
|
|
|
|
2017-04-22 17:30:27 +10:00
|
|
|
newObj->EverBound = GL_TRUE;
|
2006-06-12 16:26:29 +00:00
|
|
|
}
|
|
|
|
|
2018-01-24 09:14:35 -07:00
|
|
|
/* The _DrawArrays pointer is pointing at the VAO being unbound and
|
|
|
|
* that VAO may be in the process of being deleted. If it's not going
|
|
|
|
* to be deleted, this will have no effect, because the pointer needs
|
|
|
|
* to be updated by the VBO module anyway.
|
|
|
|
*
|
|
|
|
* Before the VBO module can update the pointer, we have to set it
|
|
|
|
* to NULL for drivers not to set up arrays which are not bound,
|
|
|
|
* or to prevent a crash if the VAO being unbound is going to be
|
|
|
|
* deleted.
|
|
|
|
*/
|
|
|
|
_mesa_set_drawing_arrays(ctx, NULL);
|
2016-08-24 08:45:05 +02:00
|
|
|
_mesa_set_draw_vao(ctx, ctx->Array._EmptyVAO, 0);
|
2014-07-11 00:05:44 +02:00
|
|
|
|
2006-06-12 16:26:29 +00:00
|
|
|
ctx->NewState |= _NEW_ARRAY;
|
2014-02-01 20:48:51 -08:00
|
|
|
_mesa_reference_vao(ctx, &ctx->Array.VAO, newObj);
|
2009-06-19 18:07:49 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-18 18:11:26 +02:00
|
|
|
void GLAPIENTRY
|
|
|
|
_mesa_BindVertexArray_no_error(GLuint id)
|
|
|
|
{
|
|
|
|
GET_CURRENT_CONTEXT(ctx);
|
|
|
|
bind_vertex_array(ctx, id, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-18 18:08:47 +02:00
|
|
|
void GLAPIENTRY
|
|
|
|
_mesa_BindVertexArray(GLuint id)
|
|
|
|
{
|
|
|
|
GET_CURRENT_CONTEXT(ctx);
|
|
|
|
bind_vertex_array(ctx, id, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-12 16:26:29 +00:00
|
|
|
/**
|
|
|
|
* Delete a set of array objects.
|
2013-11-11 13:52:45 -07:00
|
|
|
*
|
2006-06-12 16:26:29 +00:00
|
|
|
* \param n Number of array objects to delete.
|
|
|
|
* \param ids Array of \c n array object IDs.
|
|
|
|
*/
|
2017-07-18 18:17:35 +02:00
|
|
|
static void
|
|
|
|
delete_vertex_arrays(struct gl_context *ctx, GLsizei n, const GLuint *ids)
|
2006-06-12 16:26:29 +00:00
|
|
|
{
|
|
|
|
GLsizei i;
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
2014-02-01 21:28:03 -08:00
|
|
|
struct gl_vertex_array_object *obj = _mesa_lookup_vao(ctx, ids[i]);
|
2006-06-12 16:26:29 +00:00
|
|
|
|
2017-07-20 11:52:58 +02:00
|
|
|
if (obj) {
|
|
|
|
assert(obj->Name == ids[i]);
|
|
|
|
|
|
|
|
/* If the array object is currently bound, the spec says "the binding
|
|
|
|
* for that object reverts to zero and the default vertex array
|
|
|
|
* becomes current."
|
|
|
|
*/
|
|
|
|
if (obj == ctx->Array.VAO)
|
2017-07-18 18:17:35 +02:00
|
|
|
_mesa_BindVertexArray_no_error(0);
|
2017-07-20 11:52:58 +02:00
|
|
|
|
|
|
|
/* The ID is immediately freed for re-use */
|
2017-07-20 11:52:59 +02:00
|
|
|
_mesa_HashRemoveLocked(ctx->Array.Objects, obj->Name);
|
2009-05-07 14:26:17 -06:00
|
|
|
|
2015-03-02 18:25:45 +01:00
|
|
|
if (ctx->Array.LastLookedUpVAO == obj)
|
|
|
|
_mesa_reference_vao(ctx, &ctx->Array.LastLookedUpVAO, NULL);
|
2016-08-24 08:45:05 +02:00
|
|
|
if (ctx->Array._DrawVAO == obj)
|
|
|
|
_mesa_set_draw_vao(ctx, ctx->Array._EmptyVAO, 0);
|
2015-03-02 18:25:45 +01:00
|
|
|
|
2009-05-07 14:26:17 -06:00
|
|
|
/* Unreference the array object.
|
|
|
|
* If refcount hits zero, the object will be deleted.
|
|
|
|
*/
|
2014-02-01 20:48:51 -08:00
|
|
|
_mesa_reference_vao(ctx, &obj, NULL);
|
2006-06-12 16:26:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-18 18:18:59 +02:00
|
|
|
void GLAPIENTRY
|
|
|
|
_mesa_DeleteVertexArrays_no_error(GLsizei n, const GLuint *ids)
|
|
|
|
{
|
|
|
|
GET_CURRENT_CONTEXT(ctx);
|
|
|
|
delete_vertex_arrays(ctx, n, ids);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-18 18:17:35 +02:00
|
|
|
void GLAPIENTRY
|
|
|
|
_mesa_DeleteVertexArrays(GLsizei n, const GLuint *ids)
|
|
|
|
{
|
|
|
|
GET_CURRENT_CONTEXT(ctx);
|
|
|
|
|
|
|
|
if (n < 0) {
|
|
|
|
_mesa_error(ctx, GL_INVALID_VALUE, "glDeleteVertexArray(n)");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete_vertex_arrays(ctx, n, ids);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-12 16:26:29 +00:00
|
|
|
/**
|
2006-06-12 20:02:11 +00:00
|
|
|
* Generate a set of unique array object IDs and store them in \c arrays.
|
2017-04-22 17:01:15 +10:00
|
|
|
* Helper for _mesa_GenVertexArrays() and _mesa_CreateVertexArrays()
|
2015-03-02 18:22:50 +01:00
|
|
|
* below.
|
|
|
|
*
|
2006-06-12 16:26:29 +00:00
|
|
|
* \param n Number of IDs to generate.
|
2006-06-12 20:02:11 +00:00
|
|
|
* \param arrays Array of \c n locations to store the IDs.
|
2015-03-02 18:22:50 +01:00
|
|
|
* \param create Indicates that the objects should also be created.
|
|
|
|
* \param func The name of the GL entry point.
|
2006-06-12 16:26:29 +00:00
|
|
|
*/
|
2013-11-11 13:52:45 -07:00
|
|
|
static void
|
2015-03-02 18:22:50 +01:00
|
|
|
gen_vertex_arrays(struct gl_context *ctx, GLsizei n, GLuint *arrays,
|
|
|
|
bool create, const char *func)
|
2006-06-12 16:26:29 +00:00
|
|
|
{
|
|
|
|
GLuint first;
|
|
|
|
GLint i;
|
|
|
|
|
2017-07-18 15:18:35 +02:00
|
|
|
if (!arrays)
|
2006-06-12 16:26:29 +00:00
|
|
|
return;
|
|
|
|
|
2009-06-19 17:58:47 -06:00
|
|
|
first = _mesa_HashFindFreeKeyBlock(ctx->Array.Objects, n);
|
2006-06-12 16:26:29 +00:00
|
|
|
|
2015-03-02 18:22:50 +01:00
|
|
|
/* For the sake of simplicity we create the array objects in both
|
|
|
|
* the Gen* and Create* cases. The only difference is the value of
|
|
|
|
* EverBound, which is set to true in the Create* case.
|
|
|
|
*/
|
2006-06-12 16:26:29 +00:00
|
|
|
for (i = 0; i < n; i++) {
|
2014-02-01 19:36:59 -08:00
|
|
|
struct gl_vertex_array_object *obj;
|
2006-06-12 16:26:29 +00:00
|
|
|
GLuint name = first + i;
|
|
|
|
|
2015-09-27 21:28:22 +02:00
|
|
|
obj = _mesa_new_vao(ctx, name);
|
2006-06-12 16:26:29 +00:00
|
|
|
if (!obj) {
|
2015-03-02 18:22:50 +01:00
|
|
|
_mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", func);
|
2006-06-12 16:26:29 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-03-02 18:22:50 +01:00
|
|
|
obj->EverBound = create;
|
2017-07-20 11:53:00 +02:00
|
|
|
_mesa_HashInsertLocked(ctx->Array.Objects, obj->Name, obj);
|
2006-06-12 20:02:11 +00:00
|
|
|
arrays[i] = first + i;
|
2006-06-12 16:26:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-18 15:18:35 +02:00
|
|
|
static void
|
|
|
|
gen_vertex_arrays_err(struct gl_context *ctx, GLsizei n, GLuint *arrays,
|
|
|
|
bool create, const char *func)
|
|
|
|
{
|
|
|
|
if (n < 0) {
|
|
|
|
_mesa_error(ctx, GL_INVALID_VALUE, "%s(n < 0)", func);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gen_vertex_arrays(ctx, n, arrays, create, func);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-19 18:17:25 -06:00
|
|
|
/**
|
|
|
|
* ARB version of glGenVertexArrays()
|
|
|
|
* All arrays will be required to live in VBOs.
|
|
|
|
*/
|
2017-07-18 15:21:22 +02:00
|
|
|
void GLAPIENTRY
|
|
|
|
_mesa_GenVertexArrays_no_error(GLsizei n, GLuint *arrays)
|
|
|
|
{
|
|
|
|
GET_CURRENT_CONTEXT(ctx);
|
|
|
|
gen_vertex_arrays(ctx, n, arrays, false, "glGenVertexArrays");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-19 18:17:25 -06:00
|
|
|
void GLAPIENTRY
|
|
|
|
_mesa_GenVertexArrays(GLsizei n, GLuint *arrays)
|
|
|
|
{
|
|
|
|
GET_CURRENT_CONTEXT(ctx);
|
2017-07-18 15:18:35 +02:00
|
|
|
gen_vertex_arrays_err(ctx, n, arrays, false, "glGenVertexArrays");
|
2009-06-19 18:17:25 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-02 18:22:50 +01:00
|
|
|
/**
|
|
|
|
* ARB_direct_state_access
|
|
|
|
* Generates ID's and creates the array objects.
|
|
|
|
*/
|
2017-07-18 15:21:22 +02:00
|
|
|
void GLAPIENTRY
|
|
|
|
_mesa_CreateVertexArrays_no_error(GLsizei n, GLuint *arrays)
|
|
|
|
{
|
|
|
|
GET_CURRENT_CONTEXT(ctx);
|
|
|
|
gen_vertex_arrays(ctx, n, arrays, true, "glCreateVertexArrays");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-02 18:22:50 +01:00
|
|
|
void GLAPIENTRY
|
|
|
|
_mesa_CreateVertexArrays(GLsizei n, GLuint *arrays)
|
|
|
|
{
|
|
|
|
GET_CURRENT_CONTEXT(ctx);
|
2017-07-18 15:18:35 +02:00
|
|
|
gen_vertex_arrays_err(ctx, n, arrays, true, "glCreateVertexArrays");
|
2009-06-19 18:17:25 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-12 16:26:29 +00:00
|
|
|
/**
|
|
|
|
* Determine if ID is the name of an array object.
|
2013-11-11 13:52:45 -07:00
|
|
|
*
|
2006-06-12 16:26:29 +00:00
|
|
|
* \param id ID of the potential array object.
|
2013-11-11 13:52:45 -07:00
|
|
|
* \return \c GL_TRUE if \c id is the name of a array object,
|
2006-06-12 16:26:29 +00:00
|
|
|
* \c GL_FALSE otherwise.
|
|
|
|
*/
|
|
|
|
GLboolean GLAPIENTRY
|
2012-11-06 08:57:59 -08:00
|
|
|
_mesa_IsVertexArray( GLuint id )
|
2006-06-12 16:26:29 +00:00
|
|
|
{
|
2014-02-01 19:36:59 -08:00
|
|
|
struct gl_vertex_array_object * obj;
|
2006-06-12 16:26:29 +00:00
|
|
|
GET_CURRENT_CONTEXT(ctx);
|
|
|
|
ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
|
|
|
|
|
2014-02-01 21:28:03 -08:00
|
|
|
obj = _mesa_lookup_vao(ctx, id);
|
2006-06-12 16:26:29 +00:00
|
|
|
|
2017-06-20 15:13:15 +02:00
|
|
|
return obj != NULL && obj->EverBound;
|
2006-06-12 16:26:29 +00:00
|
|
|
}
|
2015-03-02 18:30:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the element array buffer binding of a vertex array object.
|
|
|
|
*
|
|
|
|
* This is the ARB_direct_state_access equivalent of
|
|
|
|
* glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer).
|
|
|
|
*/
|
2017-07-19 15:43:28 +02:00
|
|
|
static ALWAYS_INLINE void
|
|
|
|
vertex_array_element_buffer(struct gl_context *ctx, GLuint vaobj, GLuint buffer,
|
|
|
|
bool no_error)
|
2015-03-02 18:30:12 +01:00
|
|
|
{
|
|
|
|
struct gl_vertex_array_object *vao;
|
|
|
|
struct gl_buffer_object *bufObj;
|
|
|
|
|
|
|
|
ASSERT_OUTSIDE_BEGIN_END(ctx);
|
|
|
|
|
2017-07-19 15:43:28 +02:00
|
|
|
if (!no_error) {
|
|
|
|
/* The GL_ARB_direct_state_access specification says:
|
|
|
|
*
|
|
|
|
* "An INVALID_OPERATION error is generated by
|
|
|
|
* VertexArrayElementBuffer if <vaobj> is not [compatibility profile:
|
|
|
|
* zero or] the name of an existing vertex array object."
|
|
|
|
*/
|
|
|
|
vao =_mesa_lookup_vao_err(ctx, vaobj, "glVertexArrayElementBuffer");
|
|
|
|
if (!vao)
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
vao = _mesa_lookup_vao(ctx, vaobj);
|
|
|
|
}
|
2015-03-02 18:30:12 +01:00
|
|
|
|
2017-07-19 15:43:28 +02:00
|
|
|
if (buffer != 0) {
|
|
|
|
if (!no_error) {
|
|
|
|
/* The GL_ARB_direct_state_access specification says:
|
|
|
|
*
|
|
|
|
* "An INVALID_OPERATION error is generated if <buffer> is not zero
|
|
|
|
* or the name of an existing buffer object."
|
|
|
|
*/
|
|
|
|
bufObj = _mesa_lookup_bufferobj_err(ctx, buffer,
|
|
|
|
"glVertexArrayElementBuffer");
|
|
|
|
} else {
|
|
|
|
bufObj = _mesa_lookup_bufferobj(ctx, buffer);
|
|
|
|
}
|
|
|
|
} else {
|
2015-03-02 18:30:12 +01:00
|
|
|
bufObj = ctx->Shared->NullBufferObj;
|
2017-07-19 15:43:28 +02:00
|
|
|
}
|
2015-03-02 18:30:12 +01:00
|
|
|
|
|
|
|
if (bufObj)
|
|
|
|
_mesa_reference_buffer_object(ctx, &vao->IndexBufferObj, bufObj);
|
|
|
|
}
|
2015-03-02 18:56:31 +01:00
|
|
|
|
|
|
|
|
2017-07-19 15:45:01 +02:00
|
|
|
void GLAPIENTRY
|
|
|
|
_mesa_VertexArrayElementBuffer_no_error(GLuint vaobj, GLuint buffer)
|
|
|
|
{
|
|
|
|
GET_CURRENT_CONTEXT(ctx);
|
|
|
|
vertex_array_element_buffer(ctx, vaobj, buffer, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-19 15:43:28 +02:00
|
|
|
void GLAPIENTRY
|
|
|
|
_mesa_VertexArrayElementBuffer(GLuint vaobj, GLuint buffer)
|
|
|
|
{
|
|
|
|
GET_CURRENT_CONTEXT(ctx);
|
|
|
|
vertex_array_element_buffer(ctx, vaobj, buffer, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-02 18:56:31 +01:00
|
|
|
void GLAPIENTRY
|
|
|
|
_mesa_GetVertexArrayiv(GLuint vaobj, GLenum pname, GLint *param)
|
|
|
|
{
|
|
|
|
GET_CURRENT_CONTEXT(ctx);
|
|
|
|
struct gl_vertex_array_object *vao;
|
|
|
|
|
|
|
|
ASSERT_OUTSIDE_BEGIN_END(ctx);
|
|
|
|
|
|
|
|
/* The GL_ARB_direct_state_access specification says:
|
|
|
|
*
|
|
|
|
* "An INVALID_OPERATION error is generated if <vaobj> is not
|
|
|
|
* [compatibility profile: zero or] the name of an existing
|
|
|
|
* vertex array object."
|
|
|
|
*/
|
|
|
|
vao =_mesa_lookup_vao_err(ctx, vaobj, "glGetVertexArrayiv");
|
|
|
|
if (!vao)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* The GL_ARB_direct_state_access specification says:
|
|
|
|
*
|
|
|
|
* "An INVALID_ENUM error is generated if <pname> is not
|
|
|
|
* ELEMENT_ARRAY_BUFFER_BINDING."
|
|
|
|
*/
|
|
|
|
if (pname != GL_ELEMENT_ARRAY_BUFFER_BINDING) {
|
|
|
|
_mesa_error(ctx, GL_INVALID_ENUM,
|
|
|
|
"glGetVertexArrayiv(pname != "
|
|
|
|
"GL_ELEMENT_ARRAY_BUFFER_BINDING)");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
param[0] = vao->IndexBufferObj->Name;
|
|
|
|
}
|