X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fmain%2Fvarray.c;h=c2bf2951687ebd11735e9651f5a080afff720ea7;hb=0663edf85b8e055dfecf290afab1a15c68da961a;hp=77a1af09a29baac08c497542cca66b7a10fb7783;hpb=308926853d132a4d096e70447a262bef1e576789;p=mesa.git diff --git a/src/mesa/main/varray.c b/src/mesa/main/varray.c index 77a1af09a29..c2bf2951687 100644 --- a/src/mesa/main/varray.c +++ b/src/mesa/main/varray.c @@ -66,6 +66,21 @@ #define UNSIGNED_INT_10F_11F_11F_REV_BIT (1 << 14) #define ALL_TYPE_BITS ((1 << 15) - 1) +#define ATTRIB_FORMAT_TYPES_MASK (BYTE_BIT | UNSIGNED_BYTE_BIT | \ + SHORT_BIT | UNSIGNED_SHORT_BIT | \ + INT_BIT | UNSIGNED_INT_BIT | \ + HALF_BIT | FLOAT_BIT | DOUBLE_BIT | \ + FIXED_GL_BIT | \ + UNSIGNED_INT_2_10_10_10_REV_BIT | \ + INT_2_10_10_10_REV_BIT | \ + UNSIGNED_INT_10F_11F_11F_REV_BIT) + +#define ATTRIB_IFORMAT_TYPES_MASK (BYTE_BIT | UNSIGNED_BYTE_BIT | \ + SHORT_BIT | UNSIGNED_SHORT_BIT | \ + INT_BIT | UNSIGNED_INT_BIT) + +#define ATTRIB_LFORMAT_TYPES_MASK DOUBLE_BIT + /** Convert GL datatype enum into a _BIT value seen above */ static GLbitfield @@ -113,12 +128,18 @@ type_to_bit(const struct gl_context *ctx, GLenum type) * Sets the VertexBinding field in the vertex attribute given by attribIndex. */ static void -vertex_attrib_binding(struct gl_context *ctx, GLuint attribIndex, +vertex_attrib_binding(struct gl_context *ctx, + struct gl_vertex_array_object *vao, + GLuint attribIndex, GLuint bindingIndex) { - struct gl_vertex_array_object *vao = ctx->Array.VAO; struct gl_vertex_attrib_array *array = &vao->VertexAttrib[attribIndex]; + if (!_mesa_is_bufferobj(vao->VertexBinding[bindingIndex].BufferObj)) + vao->VertexAttribBufferMask &= ~VERT_BIT(attribIndex); + else + vao->VertexAttribBufferMask |= VERT_BIT(attribIndex); + if (array->VertexBinding != bindingIndex) { const GLbitfield64 array_bit = VERT_BIT(attribIndex); @@ -138,12 +159,12 @@ vertex_attrib_binding(struct gl_context *ctx, GLuint attribIndex, * Binds a buffer object to the vertex buffer binding point given by index, * and sets the Offset and Stride fields. */ -static void -bind_vertex_buffer(struct gl_context *ctx, - struct gl_vertex_array_object *vao, - GLuint index, - struct gl_buffer_object *vbo, - GLintptr offset, GLsizei stride) +void +_mesa_bind_vertex_buffer(struct gl_context *ctx, + struct gl_vertex_array_object *vao, + GLuint index, + struct gl_buffer_object *vbo, + GLintptr offset, GLsizei stride) { struct gl_vertex_buffer_binding *binding = &vao->VertexBinding[index]; @@ -158,6 +179,11 @@ bind_vertex_buffer(struct gl_context *ctx, binding->Offset = offset; binding->Stride = stride; + if (!_mesa_is_bufferobj(vbo)) + vao->VertexAttribBufferMask &= ~binding->_BoundArrays; + else + vao->VertexAttribBufferMask |= binding->_BoundArrays; + vao->NewArrays |= binding->_BoundArrays; } } @@ -168,10 +194,11 @@ bind_vertex_buffer(struct gl_context *ctx, * given by bindingIndex. */ static void -vertex_binding_divisor(struct gl_context *ctx, GLuint bindingIndex, +vertex_binding_divisor(struct gl_context *ctx, + struct gl_vertex_array_object *vao, + GLuint bindingIndex, GLuint divisor) { - struct gl_vertex_array_object *vao = ctx->Array.VAO; struct gl_vertex_buffer_binding *binding = &vao->VertexBinding[bindingIndex]; @@ -230,6 +257,52 @@ get_legal_types_mask(const struct gl_context *ctx) } +/** + * \param attrib The index of the attribute array + * \param size Components per element (1, 2, 3 or 4) + * \param type Datatype of each component (GL_FLOAT, GL_INT, etc) + * \param format Either GL_RGBA or GL_BGRA. + * \param normalized Whether integer types are converted to floats in [-1, 1] + * \param integer Integer-valued values (will not be normalized to [-1, 1]) + * \param doubles Double values not reduced to floats + * \param relativeOffset Offset of the first element relative to the binding + * offset. + * \param flush_verties Should \c FLUSH_VERTICES be invoked before updating + * state? + */ +void +_mesa_update_array_format(struct gl_context *ctx, + struct gl_vertex_array_object *vao, + GLuint attrib, GLint size, GLenum type, + GLenum format, GLboolean normalized, + GLboolean integer, GLboolean doubles, + GLuint relativeOffset, bool flush_vertices) +{ + struct gl_vertex_attrib_array *const array = &vao->VertexAttrib[attrib]; + GLint elementSize; + + assert(size <= 4); + + if (flush_vertices) { + FLUSH_VERTICES(ctx, 0); + } + + elementSize = _mesa_bytes_per_vertex_attrib(size, type); + assert(elementSize != -1); + + array->Size = size; + array->Type = type; + array->Format = format; + array->Normalized = normalized; + array->Integer = integer; + array->Doubles = doubles; + array->RelativeOffset = relativeOffset; + array->_ElementSize = elementSize; + + vao->NewArrays |= VERT_BIT(attrib); + ctx->NewState |= _NEW_ARRAY; +} + /** * Does error checking and updates the format in an attrib array. * @@ -250,15 +323,14 @@ get_legal_types_mask(const struct gl_context *ctx) static bool update_array_format(struct gl_context *ctx, const char *func, + struct gl_vertex_array_object *vao, GLuint attrib, GLbitfield legalTypesMask, GLint sizeMin, GLint sizeMax, GLint size, GLenum type, GLboolean normalized, GLboolean integer, GLboolean doubles, GLuint relativeOffset) { - struct gl_vertex_attrib_array *array; GLbitfield typeBit; - GLint elementSize; GLenum format = GL_RGBA; if (ctx->Array.LegalTypesMask == 0 || ctx->Array.LegalTypesMaskAPI != ctx->API) { @@ -282,7 +354,7 @@ update_array_format(struct gl_context *ctx, typeBit = type_to_bit(ctx, type); if (typeBit == 0x0 || (typeBit & legalTypesMask) == 0x0) { _mesa_error(ctx, GL_INVALID_ENUM, "%s(type = %s)", - func, _mesa_lookup_enum_by_nr(type)); + func, _mesa_enum_to_string(type)); return false; } @@ -315,7 +387,7 @@ update_array_format(struct gl_context *ctx, if (bgra_error) { _mesa_error(ctx, GL_INVALID_OPERATION, "%s(size=GL_BGRA and type=%s)", - func, _mesa_lookup_enum_by_nr(type)); + func, _mesa_enum_to_string(type)); return false; } @@ -359,23 +431,9 @@ update_array_format(struct gl_context *ctx, return false; } - assert(size <= 4); - - elementSize = _mesa_bytes_per_vertex_attrib(size, type); - assert(elementSize != -1); - - array = &ctx->Array.VAO->VertexAttrib[attrib]; - array->Size = size; - array->Type = type; - array->Format = format; - array->Normalized = normalized; - array->Integer = integer; - array->Doubles = doubles; - array->RelativeOffset = relativeOffset; - array->_ElementSize = elementSize; - - ctx->Array.VAO->NewArrays |= VERT_BIT(attrib); - ctx->NewState |= _NEW_ARRAY; + _mesa_update_array_format(ctx, vao, attrib, size, type, format, + normalized, integer, doubles, relativeOffset, + false); return true; } @@ -457,13 +515,14 @@ update_array(struct gl_context *ctx, return; } - if (!update_array_format(ctx, func, attrib, legalTypesMask, sizeMin, - sizeMax, size, type, normalized, integer, doubles, 0)) { + if (!update_array_format(ctx, func, ctx->Array.VAO, attrib, + legalTypesMask, sizeMin, sizeMax, + size, type, normalized, integer, doubles, 0)) { return; } /* Reset the vertex attrib binding */ - vertex_attrib_binding(ctx, attrib, attrib); + vertex_attrib_binding(ctx, ctx->Array.VAO, attrib, attrib); /* The Stride and Ptr fields are not set by update_array_format() */ array = &ctx->Array.VAO->VertexAttrib[attrib]; @@ -472,8 +531,9 @@ update_array(struct gl_context *ctx, /* Update the vertex buffer binding */ effectiveStride = stride != 0 ? stride : array->_ElementSize; - bind_vertex_buffer(ctx, ctx->Array.VAO, attrib, ctx->Array.ArrayBufferObj, - (GLintptr) ptr, effectiveStride); + _mesa_bind_vertex_buffer(ctx, ctx->Array.VAO, attrib, + ctx->Array.ArrayBufferObj, (GLintptr) ptr, + effectiveStride); } @@ -638,7 +698,7 @@ _mesa_PointSizePointerOES(GLenum type, GLsizei stride, const GLvoid *ptr) "glPointSizePointer(ES 1.x only)"); return; } - + update_array(ctx, "glPointSizePointer", VERT_ATTRIB_POINT_SIZE, legalTypes, 1, 1, 1, type, stride, GL_FALSE, GL_FALSE, GL_FALSE, ptr); @@ -716,10 +776,26 @@ _mesa_VertexAttribLPointer(GLuint index, GLint size, GLenum type, update_array(ctx, "glVertexAttribLPointer", VERT_ATTRIB_GENERIC(index), legalTypes, 1, 4, - size, type, stride, GL_TRUE, GL_FALSE, GL_TRUE, ptr); + size, type, stride, GL_FALSE, GL_FALSE, GL_TRUE, ptr); } +void +_mesa_enable_vertex_array_attrib(struct gl_context *ctx, + struct gl_vertex_array_object *vao, + unsigned attrib) +{ + assert(attrib < ARRAY_SIZE(vao->VertexAttrib)); + + if (!vao->VertexAttrib[attrib].Enabled) { + /* was disabled, now being enabled */ + FLUSH_VERTICES(ctx, _NEW_ARRAY); + vao->VertexAttrib[attrib].Enabled = GL_TRUE; + vao->_Enabled |= VERT_BIT(attrib); + vao->NewArrays |= VERT_BIT(attrib); + } +} + static void enable_vertex_array_attrib(struct gl_context *ctx, struct gl_vertex_array_object *vao, @@ -731,15 +807,7 @@ enable_vertex_array_attrib(struct gl_context *ctx, return; } - assert(VERT_ATTRIB_GENERIC(index) < ARRAY_SIZE(vao->VertexAttrib)); - - if (!vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled) { - /* was disabled, now being enabled */ - FLUSH_VERTICES(ctx, _NEW_ARRAY); - vao->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Enabled = GL_TRUE; - vao->_Enabled |= VERT_BIT_GENERIC(index); - vao->NewArrays |= VERT_BIT_GENERIC(index); - } + _mesa_enable_vertex_array_attrib(ctx, vao, VERT_ATTRIB_GENERIC(index)); } @@ -832,10 +900,11 @@ _mesa_DisableVertexArrayAttrib(GLuint vaobj, GLuint index) * not handle the 4-element GL_CURRENT_VERTEX_ATTRIB_ARB query. */ static GLuint -get_vertex_array_attrib(struct gl_context *ctx, GLuint index, GLenum pname, - const char *caller) +get_vertex_array_attrib(struct gl_context *ctx, + const struct gl_vertex_array_object *vao, + GLuint index, GLenum pname, + const char *caller) { - const struct gl_vertex_array_object *vao = ctx->Array.VAO; const struct gl_vertex_attrib_array *array; if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) { @@ -867,6 +936,11 @@ get_vertex_array_attrib(struct gl_context *ctx, GLuint index, GLenum pname, return array->Integer; } goto error; + case GL_VERTEX_ATTRIB_ARRAY_LONG: + if (_mesa_is_desktop_gl(ctx)) { + return array->Doubles; + } + goto error; case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB: if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_instanced_arrays) || _mesa_is_gles3(ctx)) { @@ -874,12 +948,12 @@ get_vertex_array_attrib(struct gl_context *ctx, GLuint index, GLenum pname, } goto error; case GL_VERTEX_ATTRIB_BINDING: - if (_mesa_is_desktop_gl(ctx)) { + if (_mesa_is_desktop_gl(ctx) || _mesa_is_gles31(ctx)) { return array->VertexBinding - VERT_ATTRIB_GENERIC0; } goto error; case GL_VERTEX_ATTRIB_RELATIVE_OFFSET: - if (_mesa_is_desktop_gl(ctx)) { + if (_mesa_is_desktop_gl(ctx) || _mesa_is_gles31(ctx)) { return array->RelativeOffset; } goto error; @@ -908,7 +982,8 @@ get_current_attrib(struct gl_context *ctx, GLuint index, const char *function) return NULL; } - assert(VERT_ATTRIB_GENERIC(index) < ARRAY_SIZE(ctx->Array.VAO->VertexAttrib)); + assert(VERT_ATTRIB_GENERIC(index) < + ARRAY_SIZE(ctx->Array.VAO->VertexAttrib)); FLUSH_CURRENT(ctx, 0); return ctx->Current.Attrib[VERT_ATTRIB_GENERIC(index)]; @@ -926,7 +1001,8 @@ _mesa_GetVertexAttribfv(GLuint index, GLenum pname, GLfloat *params) } } else { - params[0] = (GLfloat) get_vertex_array_attrib(ctx, index, pname, + params[0] = (GLfloat) get_vertex_array_attrib(ctx, ctx->Array.VAO, + index, pname, "glGetVertexAttribfv"); } } @@ -947,7 +1023,8 @@ _mesa_GetVertexAttribdv(GLuint index, GLenum pname, GLdouble *params) } } else { - params[0] = (GLdouble) get_vertex_array_attrib(ctx, index, pname, + params[0] = (GLdouble) get_vertex_array_attrib(ctx, ctx->Array.VAO, + index, pname, "glGetVertexAttribdv"); } } @@ -958,7 +1035,9 @@ _mesa_GetVertexAttribLdv(GLuint index, GLenum pname, GLdouble *params) GET_CURRENT_CONTEXT(ctx); if (pname == GL_CURRENT_VERTEX_ATTRIB_ARB) { - const GLdouble *v = (const GLdouble *)get_current_attrib(ctx, index, "glGetVertexAttribLdv"); + const GLdouble *v = + (const GLdouble *)get_current_attrib(ctx, index, + "glGetVertexAttribLdv"); if (v != NULL) { params[0] = v[0]; params[1] = v[1]; @@ -967,7 +1046,8 @@ _mesa_GetVertexAttribLdv(GLuint index, GLenum pname, GLdouble *params) } } else { - params[0] = (GLdouble) get_vertex_array_attrib(ctx, index, pname, + params[0] = (GLdouble) get_vertex_array_attrib(ctx, ctx->Array.VAO, + index, pname, "glGetVertexAttribLdv"); } } @@ -988,7 +1068,8 @@ _mesa_GetVertexAttribiv(GLuint index, GLenum pname, GLint *params) } } else { - params[0] = (GLint) get_vertex_array_attrib(ctx, index, pname, + params[0] = (GLint) get_vertex_array_attrib(ctx, ctx->Array.VAO, + index, pname, "glGetVertexAttribiv"); } } @@ -1008,7 +1089,8 @@ _mesa_GetVertexAttribIiv(GLuint index, GLenum pname, GLint *params) } } else { - params[0] = (GLint) get_vertex_array_attrib(ctx, index, pname, + params[0] = (GLint) get_vertex_array_attrib(ctx, ctx->Array.VAO, + index, pname, "glGetVertexAttribIiv"); } } @@ -1028,7 +1110,8 @@ _mesa_GetVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params) } } else { - params[0] = get_vertex_array_attrib(ctx, index, pname, + params[0] = get_vertex_array_attrib(ctx, ctx->Array.VAO, + index, pname, "glGetVertexAttribIuiv"); } } @@ -1049,9 +1132,128 @@ _mesa_GetVertexAttribPointerv(GLuint index, GLenum pname, GLvoid **pointer) return; } - assert(VERT_ATTRIB_GENERIC(index) < ARRAY_SIZE(ctx->Array.VAO->VertexAttrib)); + assert(VERT_ATTRIB_GENERIC(index) < + ARRAY_SIZE(ctx->Array.VAO->VertexAttrib)); + + *pointer = (GLvoid *) + ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Ptr; +} + + +/** ARB_direct_state_access */ +void GLAPIENTRY +_mesa_GetVertexArrayIndexediv(GLuint vaobj, GLuint index, + GLenum pname, GLint *params) +{ + GET_CURRENT_CONTEXT(ctx); + struct gl_vertex_array_object *vao; + + /* The ARB_direct_state_access specification says: + * + * "An INVALID_OPERATION error is generated if is not + * [compatibility profile: zero or] the name of an existing + * vertex array object." + */ + vao = _mesa_lookup_vao_err(ctx, vaobj, "glGetVertexArrayIndexediv"); + if (!vao) + return; + + /* The ARB_direct_state_access specification says: + * + * "For GetVertexArrayIndexediv, must be one of + * VERTEX_ATTRIB_ARRAY_ENABLED, VERTEX_ATTRIB_ARRAY_SIZE, + * VERTEX_ATTRIB_ARRAY_STRIDE, VERTEX_ATTRIB_ARRAY_TYPE, + * VERTEX_ATTRIB_ARRAY_NORMALIZED, VERTEX_ATTRIB_ARRAY_INTEGER, + * VERTEX_ATTRIB_ARRAY_LONG, VERTEX_ATTRIB_ARRAY_DIVISOR, or + * VERTEX_ATTRIB_RELATIVE_OFFSET." + * + * and: + * + * "Add GetVertexArrayIndexediv in 'Get Command' for + * VERTEX_ATTRIB_ARRAY_BUFFER_BINDING + * VERTEX_ATTRIB_BINDING, + * VERTEX_ATTRIB_RELATIVE_OFFSET, + * VERTEX_BINDING_OFFSET, and + * VERTEX_BINDING_STRIDE states" + * + * The only parameter name common to both lists is + * VERTEX_ATTRIB_RELATIVE_OFFSET. Also note that VERTEX_BINDING_BUFFER + * and VERTEX_BINDING_DIVISOR are missing from both lists. It seems + * pretty clear however that the intent is that it should be possible + * to query all vertex attrib and binding states that can be set with + * a DSA function. + */ + switch (pname) { + case GL_VERTEX_BINDING_OFFSET: + params[0] = vao->VertexBinding[VERT_ATTRIB_GENERIC(index)].Offset; + break; + case GL_VERTEX_BINDING_STRIDE: + params[0] = vao->VertexBinding[VERT_ATTRIB_GENERIC(index)].Stride; + break; + case GL_VERTEX_BINDING_DIVISOR: + params[0] = vao->VertexBinding[VERT_ATTRIB_GENERIC(index)].InstanceDivisor; + break; + case GL_VERTEX_BINDING_BUFFER: + params[0] = vao->VertexBinding[VERT_ATTRIB_GENERIC(index)].BufferObj->Name; + break; + default: + params[0] = get_vertex_array_attrib(ctx, vao, index, pname, + "glGetVertexArrayIndexediv"); + break; + } +} + + +void GLAPIENTRY +_mesa_GetVertexArrayIndexed64iv(GLuint vaobj, GLuint index, + GLenum pname, GLint64 *params) +{ + GET_CURRENT_CONTEXT(ctx); + struct gl_vertex_array_object *vao; + + /* The ARB_direct_state_access specification says: + * + * "An INVALID_OPERATION error is generated if is not + * [compatibility profile: zero or] the name of an existing + * vertex array object." + */ + vao = _mesa_lookup_vao_err(ctx, vaobj, "glGetVertexArrayIndexed64iv"); + if (!vao) + return; + + /* The ARB_direct_state_access specification says: + * + * "For GetVertexArrayIndexed64iv, must be + * VERTEX_BINDING_OFFSET." + * + * and: + * + * "An INVALID_ENUM error is generated if is not one of + * the valid values listed above for the corresponding command." + */ + if (pname != GL_VERTEX_BINDING_OFFSET) { + _mesa_error(ctx, GL_INVALID_ENUM, "glGetVertexArrayIndexed64iv(" + "pname != GL_VERTEX_BINDING_OFFSET)"); + return; + } + + /* The ARB_direct_state_access specification says: + * + * "An INVALID_VALUE error is generated if is greater than + * or equal to the value of MAX_VERTEX_ATTRIBS." + * + * Since the index refers to a buffer binding in this case, the intended + * limit must be MAX_VERTEX_ATTRIB_BINDINGS. Both limits are currently + * required to be the same, so in practice this doesn't matter. + */ + if (index >= ctx->Const.MaxVertexAttribBindings) { + _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexArrayIndexed64iv(index" + "%d >= the value of GL_MAX_VERTEX_ATTRIB_BINDINGS (%d))", + index, ctx->Const.MaxVertexAttribBindings); + return; + } - *pointer = (GLvoid *) ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Ptr; + params[0] = vao->VertexBinding[VERT_ATTRIB_GENERIC(index)].Offset; } @@ -1429,6 +1631,7 @@ _mesa_VertexAttribDivisor(GLuint index, GLuint divisor) GET_CURRENT_CONTEXT(ctx); const GLuint genericIndex = VERT_ATTRIB_GENERIC(index); + struct gl_vertex_array_object * const vao = ctx->Array.VAO; if (!ctx->Extensions.ARB_instanced_arrays) { _mesa_error(ctx, GL_INVALID_OPERATION, "glVertexAttribDivisor()"); @@ -1441,7 +1644,7 @@ _mesa_VertexAttribDivisor(GLuint index, GLuint divisor) return; } - assert(genericIndex < ARRAY_SIZE(ctx->Array.VAO->VertexAttrib)); + assert(genericIndex < ARRAY_SIZE(vao->VertexAttrib)); /* The ARB_vertex_attrib_binding spec says: * @@ -1454,8 +1657,8 @@ _mesa_VertexAttribDivisor(GLuint index, GLuint divisor) * VertexAttribBinding(index, index); * VertexBindingDivisor(index, divisor);" */ - vertex_attrib_binding(ctx, genericIndex, genericIndex); - vertex_binding_divisor(ctx, genericIndex, divisor); + vertex_attrib_binding(ctx, vao, genericIndex, genericIndex); + vertex_binding_divisor(ctx, vao, genericIndex, divisor); } @@ -1488,7 +1691,8 @@ _mesa_primitive_restart_index(const struct gl_context *ctx, GLenum ib_type) * GL_ARB_vertex_attrib_binding */ static void -vertex_array_vertex_buffer(struct gl_context *ctx, struct gl_vertex_array_object *vao, +vertex_array_vertex_buffer(struct gl_context *ctx, + struct gl_vertex_array_object *vao, GLuint bindingIndex, GLuint buffer, GLintptr offset, GLsizei stride, const char *func) { @@ -1527,18 +1731,23 @@ vertex_array_vertex_buffer(struct gl_context *ctx, struct gl_vertex_array_object return; } - if (ctx->API == API_OPENGL_CORE && ctx->Version >= 44 && + if (((ctx->API == API_OPENGL_CORE && ctx->Version >= 44) || _mesa_is_gles31(ctx)) && stride > ctx->Const.MaxVertexAttribStride) { _mesa_error(ctx, GL_INVALID_VALUE, "%s(stride=%d > " "GL_MAX_VERTEX_ATTRIB_STRIDE)", func, stride); return; } - if (buffer == vao->VertexBinding[VERT_ATTRIB_GENERIC(bindingIndex)].BufferObj->Name) { + if (buffer == + vao->VertexBinding[VERT_ATTRIB_GENERIC(bindingIndex)].BufferObj->Name) { vbo = vao->VertexBinding[VERT_ATTRIB_GENERIC(bindingIndex)].BufferObj; } else if (buffer != 0) { vbo = _mesa_lookup_bufferobj(ctx, buffer); + if (!vbo && _mesa_is_gles31(ctx)) { + _mesa_error(ctx, GL_INVALID_OPERATION, "%s(non-gen name)", func); + return; + } /* From the GL_ARB_vertex_attrib_array spec: * * "[Core profile only:] @@ -1549,8 +1758,7 @@ vertex_array_vertex_buffer(struct gl_context *ctx, struct gl_vertex_array_object * Otherwise, we fall back to the same compat profile behavior as other * object references (automatically gen it). */ - if (!_mesa_handle_bind_buffer_gen(ctx, GL_ARRAY_BUFFER, buffer, - &vbo, func)) + if (!_mesa_handle_bind_buffer_gen(ctx, buffer, &vbo, func)) return; } else { /* The ARB_vertex_attrib_binding spec says: @@ -1561,8 +1769,8 @@ vertex_array_vertex_buffer(struct gl_context *ctx, struct gl_vertex_array_object vbo = ctx->Shared->NullBufferObj; } - bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(bindingIndex), - vbo, offset, stride); + _mesa_bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(bindingIndex), + vbo, offset, stride); } @@ -1577,7 +1785,7 @@ _mesa_BindVertexBuffer(GLuint bindingIndex, GLuint buffer, GLintptr offset, * "An INVALID_OPERATION error is generated if no vertex array object * is bound." */ - if (ctx->API == API_OPENGL_CORE && + if ((ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) && ctx->Array.VAO == ctx->Array.DefaultVAO) { _mesa_error(ctx, GL_INVALID_OPERATION, "glBindVertexBuffer(No array object bound)"); @@ -1649,8 +1857,8 @@ vertex_array_vertex_buffers(struct gl_context *ctx, struct gl_buffer_object *vbo = ctx->Shared->NullBufferObj; for (i = 0; i < count; i++) - bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(first + i), - vbo, 0, 16); + _mesa_bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(first + i), + vbo, 0, 16); return; } @@ -1721,8 +1929,8 @@ vertex_array_vertex_buffers(struct gl_context *ctx, vbo = ctx->Shared->NullBufferObj; } - bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(first + i), - vbo, offsets[i], strides[i]); + _mesa_bind_vertex_buffer(ctx, vao, VERT_ATTRIB_GENERIC(first + i), + vbo, offsets[i], strides[i]); } _mesa_end_bufferobj_lookups(ctx); @@ -1777,19 +1985,13 @@ _mesa_VertexArrayVertexBuffers(GLuint vaobj, GLuint first, GLsizei count, } -void GLAPIENTRY -_mesa_VertexAttribFormat(GLuint attribIndex, GLint size, GLenum type, - GLboolean normalized, GLuint relativeOffset) +static void +vertex_attrib_format(GLuint attribIndex, GLint size, GLenum type, + GLboolean normalized, GLboolean integer, + GLboolean doubles, GLbitfield legalTypes, + GLsizei maxSize, GLuint relativeOffset, + const char *func) { - const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT | - SHORT_BIT | UNSIGNED_SHORT_BIT | - INT_BIT | UNSIGNED_INT_BIT | - HALF_BIT | FLOAT_BIT | DOUBLE_BIT | - FIXED_GL_BIT | - UNSIGNED_INT_2_10_10_10_REV_BIT | - INT_2_10_10_10_REV_BIT | - UNSIGNED_INT_10F_11F_11F_REV_BIT); - GET_CURRENT_CONTEXT(ctx); ASSERT_OUTSIDE_BEGIN_END(ctx); @@ -1799,11 +2001,16 @@ _mesa_VertexAttribFormat(GLuint attribIndex, GLint size, GLenum type, * conditions: * - if no vertex array object is currently bound (see section 2.10); * - ..." + * + * This error condition only applies to VertexAttribFormat and + * VertexAttribIFormat in the extension spec, but we assume that this + * is an oversight. In the OpenGL 4.3 (Core Profile) spec, it applies + * to all three functions. */ - if (ctx->API == API_OPENGL_CORE && + if ((ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) && ctx->Array.VAO == ctx->Array.DefaultVAO) { _mesa_error(ctx, GL_INVALID_OPERATION, - "glVertexAttribFormat(No array object bound)"); + "%s(No array object bound)", func); return; } @@ -1814,18 +2021,29 @@ _mesa_VertexAttribFormat(GLuint attribIndex, GLint size, GLenum type, */ if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) { _mesa_error(ctx, GL_INVALID_VALUE, - "glVertexAttribFormat(attribindex=%u > " + "%s(attribindex=%u > " "GL_MAX_VERTEX_ATTRIBS)", - attribIndex); + func, attribIndex); return; } FLUSH_VERTICES(ctx, 0); - update_array_format(ctx, "glVertexAttribFormat", + update_array_format(ctx, func, ctx->Array.VAO, VERT_ATTRIB_GENERIC(attribIndex), - legalTypes, 1, BGRA_OR_4, size, type, normalized, - GL_FALSE, GL_FALSE, relativeOffset); + legalTypes, 1, maxSize, size, type, + normalized, integer, doubles, relativeOffset); +} + + +void GLAPIENTRY +_mesa_VertexAttribFormat(GLuint attribIndex, GLint size, GLenum type, + GLboolean normalized, GLuint relativeOffset) +{ + vertex_attrib_format(attribIndex, size, type, normalized, + GL_FALSE, GL_FALSE, ATTRIB_FORMAT_TYPES_MASK, + BGRA_OR_4, relativeOffset, + "glVertexAttribFormat"); } @@ -1833,94 +2051,137 @@ void GLAPIENTRY _mesa_VertexAttribIFormat(GLuint attribIndex, GLint size, GLenum type, GLuint relativeOffset) { - const GLbitfield legalTypes = (BYTE_BIT | UNSIGNED_BYTE_BIT | - SHORT_BIT | UNSIGNED_SHORT_BIT | - INT_BIT | UNSIGNED_INT_BIT); + vertex_attrib_format(attribIndex, size, type, GL_FALSE, + GL_TRUE, GL_FALSE, ATTRIB_IFORMAT_TYPES_MASK, 4, + relativeOffset, "glVertexAttribIFormat"); +} + +void GLAPIENTRY +_mesa_VertexAttribLFormat(GLuint attribIndex, GLint size, GLenum type, + GLuint relativeOffset) +{ + vertex_attrib_format(attribIndex, size, type, GL_FALSE, GL_FALSE, + GL_TRUE, ATTRIB_LFORMAT_TYPES_MASK, 4, + relativeOffset, "glVertexAttribLFormat"); +} + + +static void +vertex_array_attrib_format(GLuint vaobj, GLuint attribIndex, GLint size, + GLenum type, GLboolean normalized, + GLboolean integer, GLboolean doubles, + GLbitfield legalTypes, GLsizei maxSize, + GLuint relativeOffset, const char *func) +{ GET_CURRENT_CONTEXT(ctx); + struct gl_vertex_array_object *vao; + ASSERT_OUTSIDE_BEGIN_END(ctx); - /* The ARB_vertex_attrib_binding spec says: + /* The ARB_direct_state_access spec says: * - * "An INVALID_OPERATION error is generated under any of the following - * conditions: - * - if no vertex array object is currently bound (see section 2.10); - * - ..." + * "An INVALID_OPERATION error is generated by VertexArrayAttrib*Format + * if is not [compatibility profile: zero or] the name of an + * existing vertex array object." */ - if (ctx->API == API_OPENGL_CORE && - ctx->Array.VAO == ctx->Array.DefaultVAO) { - _mesa_error(ctx, GL_INVALID_OPERATION, - "glVertexAttribIFormat(No array object bound)"); + vao = _mesa_lookup_vao_err(ctx, vaobj, func); + if (!vao) return; - } /* The ARB_vertex_attrib_binding spec says: * - * "The error INVALID_VALUE is generated if index is greater than - * or equal to the value of MAX_VERTEX_ATTRIBS." + * "The error INVALID_VALUE is generated if index is greater than or equal + * to the value of MAX_VERTEX_ATTRIBS." */ if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) { _mesa_error(ctx, GL_INVALID_VALUE, - "glVertexAttribIFormat(attribindex=%u > " - "GL_MAX_VERTEX_ATTRIBS)", - attribIndex); + "%s(attribindex=%u > GL_MAX_VERTEX_ATTRIBS)", + func, attribIndex); return; } FLUSH_VERTICES(ctx, 0); - update_array_format(ctx, "glVertexAttribIFormat", + update_array_format(ctx, func, vao, VERT_ATTRIB_GENERIC(attribIndex), - legalTypes, 1, 4, size, type, GL_FALSE, GL_TRUE, GL_FALSE, - relativeOffset); + legalTypes, 1, maxSize, size, type, normalized, + integer, doubles, relativeOffset); } void GLAPIENTRY -_mesa_VertexAttribLFormat(GLuint attribIndex, GLint size, GLenum type, - GLuint relativeOffset) +_mesa_VertexArrayAttribFormat(GLuint vaobj, GLuint attribIndex, GLint size, + GLenum type, GLboolean normalized, + GLuint relativeOffset) { - const GLbitfield legalTypes = DOUBLE_BIT; + vertex_array_attrib_format(vaobj, attribIndex, size, type, normalized, + GL_FALSE, GL_FALSE, ATTRIB_FORMAT_TYPES_MASK, + BGRA_OR_4, relativeOffset, + "glVertexArrayAttribFormat"); +} - GET_CURRENT_CONTEXT(ctx); - ASSERT_OUTSIDE_BEGIN_END(ctx); - /* Page 298 of the PDF of the OpenGL 4.3 (Core Profile) spec says: - * - * "An INVALID_OPERATION error is generated under any of the following - * conditions: - * • if no vertex array object is currently bound (see section 10.4); - * • ..." - * - * This language is missing from the extension spec, but we assume - * that this is an oversight. - */ - if (ctx->API == API_OPENGL_CORE && - ctx->Array.VAO == ctx->Array.DefaultVAO) { - _mesa_error(ctx, GL_INVALID_OPERATION, - "glVertexAttribLFormat(No array object bound)"); - return; - } +void GLAPIENTRY +_mesa_VertexArrayAttribIFormat(GLuint vaobj, GLuint attribIndex, + GLint size, GLenum type, + GLuint relativeOffset) +{ + vertex_array_attrib_format(vaobj, attribIndex, size, type, GL_FALSE, + GL_TRUE, GL_FALSE, ATTRIB_IFORMAT_TYPES_MASK, + 4, relativeOffset, + "glVertexArrayAttribIFormat"); +} + + +void GLAPIENTRY +_mesa_VertexArrayAttribLFormat(GLuint vaobj, GLuint attribIndex, + GLint size, GLenum type, + GLuint relativeOffset) +{ + vertex_array_attrib_format(vaobj, attribIndex, size, type, GL_FALSE, + GL_FALSE, GL_TRUE, ATTRIB_LFORMAT_TYPES_MASK, + 4, relativeOffset, + "glVertexArrayAttribLFormat"); +} + + +static void +vertex_array_attrib_binding(struct gl_context *ctx, + struct gl_vertex_array_object *vao, + GLuint attribIndex, GLuint bindingIndex, + const char *func) +{ + ASSERT_OUTSIDE_BEGIN_END(ctx); /* The ARB_vertex_attrib_binding spec says: * - * "The error INVALID_VALUE is generated if is greater than - * or equal to the value of MAX_VERTEX_ATTRIBS." + * " must be less than the value of MAX_VERTEX_ATTRIBS and + * must be less than the value of + * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE + * is generated." */ if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) { _mesa_error(ctx, GL_INVALID_VALUE, - "glVertexAttribLFormat(attribindex=%u > " + "%s(attribindex=%u >= " "GL_MAX_VERTEX_ATTRIBS)", - attribIndex); + func, attribIndex); return; } - FLUSH_VERTICES(ctx, 0); + if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) { + _mesa_error(ctx, GL_INVALID_VALUE, + "%s(bindingindex=%u >= " + "GL_MAX_VERTEX_ATTRIB_BINDINGS)", + func, bindingIndex); + return; + } - update_array_format(ctx, "glVertexAttribLFormat", - VERT_ATTRIB_GENERIC(attribIndex), - legalTypes, 1, 4, size, type, GL_FALSE, GL_FALSE, GL_TRUE, - relativeOffset); + assert(VERT_ATTRIB_GENERIC(attribIndex) < ARRAY_SIZE(vao->VertexAttrib)); + + vertex_attrib_binding(ctx, vao, + VERT_ATTRIB_GENERIC(attribIndex), + VERT_ATTRIB_GENERIC(bindingIndex)); } @@ -1928,48 +2189,73 @@ void GLAPIENTRY _mesa_VertexAttribBinding(GLuint attribIndex, GLuint bindingIndex) { GET_CURRENT_CONTEXT(ctx); - ASSERT_OUTSIDE_BEGIN_END(ctx); /* The ARB_vertex_attrib_binding spec says: * * "An INVALID_OPERATION error is generated if no vertex array object * is bound." */ - if (ctx->API == API_OPENGL_CORE && + if ((ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) && ctx->Array.VAO == ctx->Array.DefaultVAO) { _mesa_error(ctx, GL_INVALID_OPERATION, "glVertexAttribBinding(No array object bound)"); return; } - /* The ARB_vertex_attrib_binding spec says: + vertex_array_attrib_binding(ctx, ctx->Array.VAO, + attribIndex, bindingIndex, + "glVertexAttribBinding"); +} + + +void GLAPIENTRY +_mesa_VertexArrayAttribBinding(GLuint vaobj, GLuint attribIndex, GLuint bindingIndex) +{ + GET_CURRENT_CONTEXT(ctx); + struct gl_vertex_array_object *vao; + + /* The ARB_direct_state_access specification says: * - * " must be less than the value of MAX_VERTEX_ATTRIBS and - * must be less than the value of - * MAX_VERTEX_ATTRIB_BINDINGS, otherwise the error INVALID_VALUE - * is generated." + * "An INVALID_OPERATION error is generated by VertexArrayAttribBinding + * if is not [compatibility profile: zero or] the name of an + * existing vertex array object." */ - if (attribIndex >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) { - _mesa_error(ctx, GL_INVALID_VALUE, - "glVertexAttribBinding(attribindex=%u >= " - "GL_MAX_VERTEX_ATTRIBS)", - attribIndex); + vao = _mesa_lookup_vao_err(ctx, vaobj, "glVertexArrayAttribBinding"); + if (!vao) + return; + + vertex_array_attrib_binding(ctx, vao, attribIndex, bindingIndex, + "glVertexArrayAttribBinding"); +} + + +static void +vertex_array_binding_divisor(struct gl_context *ctx, + struct gl_vertex_array_object *vao, + GLuint bindingIndex, GLuint divisor, + const char *func) +{ + ASSERT_OUTSIDE_BEGIN_END(ctx); + + if (!ctx->Extensions.ARB_instanced_arrays) { + _mesa_error(ctx, GL_INVALID_OPERATION, "%s()", func); return; } + /* The ARB_vertex_attrib_binding spec says: + * + * "An INVALID_VALUE error is generated if is greater + * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS." + */ if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) { _mesa_error(ctx, GL_INVALID_VALUE, - "glVertexAttribBinding(bindingindex=%u >= " + "%s(bindingindex=%u > " "GL_MAX_VERTEX_ATTRIB_BINDINGS)", - bindingIndex); + func, bindingIndex); return; } - assert(VERT_ATTRIB_GENERIC(attribIndex) < - ARRAY_SIZE(ctx->Array.VAO->VertexAttrib)); - - vertex_attrib_binding(ctx, VERT_ATTRIB_GENERIC(attribIndex), - VERT_ATTRIB_GENERIC(bindingIndex)); + vertex_binding_divisor(ctx, vao, VERT_ATTRIB_GENERIC(bindingIndex), divisor); } @@ -1977,39 +2263,44 @@ void GLAPIENTRY _mesa_VertexBindingDivisor(GLuint bindingIndex, GLuint divisor) { GET_CURRENT_CONTEXT(ctx); - ASSERT_OUTSIDE_BEGIN_END(ctx); - - if (!ctx->Extensions.ARB_instanced_arrays) { - _mesa_error(ctx, GL_INVALID_OPERATION, "glVertexBindingDivisor()"); - return; - } /* The ARB_vertex_attrib_binding spec says: * * "An INVALID_OPERATION error is generated if no vertex array object * is bound." */ - if (ctx->API == API_OPENGL_CORE && + if ((ctx->API == API_OPENGL_CORE || _mesa_is_gles31(ctx)) && ctx->Array.VAO == ctx->Array.DefaultVAO) { _mesa_error(ctx, GL_INVALID_OPERATION, "glVertexBindingDivisor(No array object bound)"); return; } - /* The ARB_vertex_attrib_binding spec says: + vertex_array_binding_divisor(ctx, ctx->Array.VAO, + bindingIndex, divisor, + "glVertexBindingDivisor"); +} + + +void GLAPIENTRY +_mesa_VertexArrayBindingDivisor(GLuint vaobj, GLuint bindingIndex, + GLuint divisor) +{ + struct gl_vertex_array_object *vao; + GET_CURRENT_CONTEXT(ctx); + + /* The ARB_direct_state_access specification says: * - * "An INVALID_VALUE error is generated if is greater - * than or equal to the value of MAX_VERTEX_ATTRIB_BINDINGS." + * "An INVALID_OPERATION error is generated by VertexArrayBindingDivisor + * if is not [compatibility profile: zero or] the name of an + * existing vertex array object." */ - if (bindingIndex >= ctx->Const.MaxVertexAttribBindings) { - _mesa_error(ctx, GL_INVALID_VALUE, - "glVertexBindingDivisor(bindingindex=%u > " - "GL_MAX_VERTEX_ATTRIB_BINDINGS)", - bindingIndex); - return; - } + vao = _mesa_lookup_vao_err(ctx, vaobj, "glVertexArrayBindingDivisor"); + if (!vao) + return; - vertex_binding_divisor(ctx, VERT_ATTRIB_GENERIC(bindingIndex), divisor); + vertex_array_binding_divisor(ctx, vao, bindingIndex, divisor, + "glVertexArrayBindingDivisor"); } @@ -2078,10 +2369,10 @@ print_array(const char *name, GLint index, const struct gl_client_array *array) fprintf(stderr, " %s[%d]: ", name, index); else fprintf(stderr, " %s: ", name); - fprintf(stderr, "Ptr=%p, Type=0x%x, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %lu)\n", - array->Ptr, array->Type, array->Size, - array->_ElementSize, array->StrideB, - array->BufferObj->Name, (unsigned long) array->BufferObj->Size); + fprintf(stderr, "Ptr=%p, Type=%s, Size=%d, ElemSize=%u, Stride=%d, Buffer=%u(Size %lu)\n", + array->Ptr, _mesa_enum_to_string(array->Type), array->Size, + array->_ElementSize, array->StrideB, array->BufferObj->Name, + (unsigned long) array->BufferObj->Size); } @@ -2113,10 +2404,10 @@ _mesa_print_arrays(struct gl_context *ctx) /** * Initialize vertex array state for given context. */ -void +void _mesa_init_varray(struct gl_context *ctx) { - ctx->Array.DefaultVAO = ctx->Driver.NewArrayObject(ctx, 0); + ctx->Array.DefaultVAO = _mesa_new_vao(ctx, 0); _mesa_reference_vao(ctx, &ctx->Array.VAO, ctx->Array.DefaultVAO); ctx->Array.ActiveTexture = 0; /* GL_ARB_multitexture */ @@ -2139,7 +2430,7 @@ delete_arrayobj_cb(GLuint id, void *data, void *userData) /** * Free vertex array state for given context. */ -void +void _mesa_free_varray_data(struct gl_context *ctx) { _mesa_HashDeleteAll(ctx->Array.Objects, delete_arrayobj_cb, ctx);