X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fmain%2Fvarray.c;h=c4283551882ea7286b45ccb86c3fe6ece3e57011;hb=78a391ed8311fc5215347f8775bf0aa29568b78d;hp=3bab9850588743e4a97d82a7a557c497471ce88c;hpb=2f11e92cef51c88a09bc778e2ceca4ab50cf0017;p=mesa.git diff --git a/src/mesa/main/varray.c b/src/mesa/main/varray.c index 3bab9850588..c4283551882 100644 --- a/src/mesa/main/varray.c +++ b/src/mesa/main/varray.c @@ -102,6 +102,7 @@ type_to_bit(const struct gl_context *ctx, GLenum type) case GL_UNSIGNED_INT: return UNSIGNED_INT_BIT; case GL_HALF_FLOAT: + case GL_HALF_FLOAT_OES: if (ctx->Extensions.ARB_half_float_vertex) return HALF_BIT; else @@ -125,7 +126,8 @@ type_to_bit(const struct gl_context *ctx, GLenum type) /** - * Sets the VertexBinding field in the vertex attribute given by attribIndex. + * Sets the BufferBindingIndex field for the vertex attribute given by + * attribIndex. */ static void vertex_attrib_binding(struct gl_context *ctx, @@ -133,17 +135,22 @@ vertex_attrib_binding(struct gl_context *ctx, GLuint attribIndex, GLuint bindingIndex) { - struct gl_vertex_attrib_array *array = &vao->VertexAttrib[attribIndex]; + struct gl_array_attributes *array = &vao->VertexAttrib[attribIndex]; - if (array->VertexBinding != bindingIndex) { + if (!_mesa_is_bufferobj(vao->BufferBinding[bindingIndex].BufferObj)) + vao->VertexAttribBufferMask &= ~VERT_BIT(attribIndex); + else + vao->VertexAttribBufferMask |= VERT_BIT(attribIndex); + + if (array->BufferBindingIndex != bindingIndex) { const GLbitfield64 array_bit = VERT_BIT(attribIndex); FLUSH_VERTICES(ctx, _NEW_ARRAY); - vao->VertexBinding[array->VertexBinding]._BoundArrays &= ~array_bit; - vao->VertexBinding[bindingIndex]._BoundArrays |= array_bit; + vao->BufferBinding[array->BufferBindingIndex]._BoundArrays &= ~array_bit; + vao->BufferBinding[bindingIndex]._BoundArrays |= array_bit; - array->VertexBinding = bindingIndex; + array->BufferBindingIndex = bindingIndex; vao->NewArrays |= array_bit; } @@ -154,14 +161,14 @@ vertex_attrib_binding(struct gl_context *ctx, * 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]; + struct gl_vertex_buffer_binding *binding = &vao->BufferBinding[index]; if (binding->BufferObj != vbo || binding->Offset != offset || @@ -174,6 +181,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; } } @@ -190,7 +202,7 @@ vertex_binding_divisor(struct gl_context *ctx, GLuint divisor) { struct gl_vertex_buffer_binding *binding = - &vao->VertexBinding[bindingIndex]; + &vao->BufferBinding[bindingIndex]; if (binding->InstanceDivisor != divisor) { FLUSH_VERTICES(ctx, _NEW_ARRAY); @@ -225,8 +237,10 @@ get_legal_types_mask(const struct gl_context *ctx) legalTypesMask &= ~(UNSIGNED_INT_BIT | INT_BIT | UNSIGNED_INT_2_10_10_10_REV_BIT | - INT_2_10_10_10_REV_BIT | - HALF_BIT); + INT_2_10_10_10_REV_BIT); + + if (!_mesa_has_OES_vertex_half_float(ctx)) + legalTypesMask &= ~HALF_BIT; } } else { @@ -247,6 +261,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_array_attributes *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. * @@ -274,11 +334,12 @@ update_array_format(struct gl_context *ctx, GLboolean normalized, GLboolean integer, GLboolean doubles, GLuint relativeOffset) { - struct gl_vertex_attrib_array *array; GLbitfield typeBit; - GLint elementSize; GLenum format = GL_RGBA; + /* at most, one of these bools can be true */ + assert((int) normalized + (int) integer + (int) doubles <= 1); + if (ctx->Array.LegalTypesMask == 0 || ctx->Array.LegalTypesMaskAPI != ctx->API) { /* Compute the LegalTypesMask only once, unless the context API has * changed, in which case we want to compute it again. We can't do this @@ -377,23 +438,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 = &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; - - 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; } @@ -425,7 +472,8 @@ update_array(struct gl_context *ctx, GLboolean normalized, GLboolean integer, GLboolean doubles, const GLvoid *ptr) { - struct gl_vertex_attrib_array *array; + struct gl_vertex_array_object *vao = ctx->Array.VAO; + struct gl_array_attributes *array; GLsizei effectiveStride; /* Page 407 (page 423 of the PDF) of the OpenGL 3.0 spec says: @@ -438,8 +486,7 @@ update_array(struct gl_context *ctx, * * The check for VBOs is handled below. */ - if (ctx->API == API_OPENGL_CORE - && (ctx->Array.VAO == ctx->Array.DefaultVAO)) { + if (ctx->API == API_OPENGL_CORE && (vao == ctx->Array.DefaultVAO)) { _mesa_error(ctx, GL_INVALID_OPERATION, "%s(no array object bound)", func); return; @@ -469,30 +516,31 @@ update_array(struct gl_context *ctx, * to the ARRAY_BUFFER buffer object binding point (see section * 2.9.6), and the pointer argument is not NULL." */ - if (ptr != NULL && ctx->Array.VAO->ARBsemantics && + if (ptr != NULL && vao->ARBsemantics && !_mesa_is_bufferobj(ctx->Array.ArrayBufferObj)) { _mesa_error(ctx, GL_INVALID_OPERATION, "%s(non-VBO array)", func); return; } - if (!update_array_format(ctx, func, ctx->Array.VAO, attrib, + if (!update_array_format(ctx, func, vao, attrib, legalTypesMask, sizeMin, sizeMax, size, type, normalized, integer, doubles, 0)) { return; } /* Reset the vertex attrib binding */ - vertex_attrib_binding(ctx, ctx->Array.VAO, attrib, attrib); + vertex_attrib_binding(ctx, vao, attrib, attrib); /* The Stride and Ptr fields are not set by update_array_format() */ - array = &ctx->Array.VAO->VertexAttrib[attrib]; + array = &vao->VertexAttrib[attrib]; array->Stride = stride; - array->Ptr = (const GLvoid *) ptr; + array->Ptr = ptr; /* 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, vao, attrib, + ctx->Array.ArrayBufferObj, (GLintptr) ptr, + effectiveStride); } @@ -657,7 +705,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); @@ -735,10 +783,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, @@ -750,15 +814,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)); } @@ -856,7 +912,7 @@ get_vertex_array_attrib(struct gl_context *ctx, GLuint index, GLenum pname, const char *caller) { - const struct gl_vertex_attrib_array *array; + const struct gl_array_attributes *array; if (index >= ctx->Const.Program[MESA_SHADER_VERTEX].MaxAttribs) { _mesa_error(ctx, GL_INVALID_VALUE, "%s(index=%u)", caller, index); @@ -879,7 +935,7 @@ get_vertex_array_attrib(struct gl_context *ctx, case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB: return array->Normalized; case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB: - return vao->VertexBinding[array->VertexBinding].BufferObj->Name; + return vao->BufferBinding[array->BufferBindingIndex].BufferObj->Name; case GL_VERTEX_ATTRIB_ARRAY_INTEGER: if ((_mesa_is_desktop_gl(ctx) && (ctx->Version >= 30 || ctx->Extensions.EXT_gpu_shader4)) @@ -895,16 +951,16 @@ get_vertex_array_attrib(struct gl_context *ctx, case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB: if ((_mesa_is_desktop_gl(ctx) && ctx->Extensions.ARB_instanced_arrays) || _mesa_is_gles3(ctx)) { - return vao->VertexBinding[array->VertexBinding].InstanceDivisor; + return vao->BufferBinding[array->BufferBindingIndex].InstanceDivisor; } goto error; case GL_VERTEX_ATTRIB_BINDING: - if (_mesa_is_desktop_gl(ctx)) { - return array->VertexBinding - VERT_ATTRIB_GENERIC0; + if (_mesa_is_desktop_gl(ctx) || _mesa_is_gles31(ctx)) { + return array->BufferBindingIndex - 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; @@ -933,7 +989,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)]; @@ -985,7 +1042,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]; @@ -1080,9 +1139,11 @@ _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; + *pointer = (GLvoid *) + ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_GENERIC(index)].Ptr; } @@ -1131,16 +1192,16 @@ _mesa_GetVertexArrayIndexediv(GLuint vaobj, GLuint index, */ switch (pname) { case GL_VERTEX_BINDING_OFFSET: - params[0] = vao->VertexBinding[VERT_ATTRIB_GENERIC(index)].Offset; + params[0] = vao->BufferBinding[VERT_ATTRIB_GENERIC(index)].Offset; break; case GL_VERTEX_BINDING_STRIDE: - params[0] = vao->VertexBinding[VERT_ATTRIB_GENERIC(index)].Stride; + params[0] = vao->BufferBinding[VERT_ATTRIB_GENERIC(index)].Stride; break; case GL_VERTEX_BINDING_DIVISOR: - params[0] = vao->VertexBinding[VERT_ATTRIB_GENERIC(index)].InstanceDivisor; + params[0] = vao->BufferBinding[VERT_ATTRIB_GENERIC(index)].InstanceDivisor; break; case GL_VERTEX_BINDING_BUFFER: - params[0] = vao->VertexBinding[VERT_ATTRIB_GENERIC(index)].BufferObj->Name; + params[0] = vao->BufferBinding[VERT_ATTRIB_GENERIC(index)].BufferObj->Name; break; default: params[0] = get_vertex_array_attrib(ctx, vao, index, pname, @@ -1193,13 +1254,13 @@ _mesa_GetVertexArrayIndexed64iv(GLuint vaobj, GLuint index, * 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))", + _mesa_error(ctx, GL_INVALID_VALUE, "glGetVertexArrayIndexed64iv(index" + "%d >= the value of GL_MAX_VERTEX_ATTRIB_BINDINGS (%d))", index, ctx->Const.MaxVertexAttribBindings); return; } - params[0] = vao->VertexBinding[VERT_ATTRIB_GENERIC(index)].Offset; + params[0] = vao->BufferBinding[VERT_ATTRIB_GENERIC(index)].Offset; } @@ -1637,7 +1698,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) { @@ -1676,18 +1738,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) { - vbo = vao->VertexBinding[VERT_ATTRIB_GENERIC(bindingIndex)].BufferObj; + if (buffer == + vao->BufferBinding[VERT_ATTRIB_GENERIC(bindingIndex)].BufferObj->Name) { + vbo = vao->BufferBinding[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:] @@ -1698,8 +1765,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: @@ -1710,8 +1776,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); } @@ -1726,7 +1792,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)"); @@ -1798,8 +1864,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; } @@ -1857,7 +1923,7 @@ vertex_array_vertex_buffers(struct gl_context *ctx, if (buffers[i]) { struct gl_vertex_buffer_binding *binding = - &vao->VertexBinding[VERT_ATTRIB_GENERIC(first + i)]; + &vao->BufferBinding[VERT_ATTRIB_GENERIC(first + i)]; if (buffers[i] == binding->BufferObj->Name) vbo = binding->BufferObj; @@ -1870,8 +1936,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); @@ -1948,7 +2014,7 @@ vertex_attrib_format(GLuint attribIndex, GLint size, GLenum type, * 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, "%s(No array object bound)", func); @@ -2136,7 +2202,7 @@ _mesa_VertexAttribBinding(GLuint attribIndex, GLuint bindingIndex) * "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)"); @@ -2210,7 +2276,7 @@ _mesa_VertexBindingDivisor(GLuint bindingIndex, GLuint divisor) * "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)"); @@ -2224,7 +2290,8 @@ _mesa_VertexBindingDivisor(GLuint bindingIndex, GLuint divisor) void GLAPIENTRY -_mesa_VertexArrayBindingDivisor(GLuint vaobj, GLuint bindingIndex, GLuint divisor) +_mesa_VertexArrayBindingDivisor(GLuint vaobj, GLuint bindingIndex, + GLuint divisor) { struct gl_vertex_array_object *vao; GET_CURRENT_CONTEXT(ctx); @@ -2249,16 +2316,14 @@ _mesa_VertexArrayBindingDivisor(GLuint vaobj, GLuint bindingIndex, GLuint diviso */ void _mesa_copy_client_array(struct gl_context *ctx, - struct gl_client_array *dst, - struct gl_client_array *src) + struct gl_vertex_array *dst, + struct gl_vertex_array *src) { dst->Size = src->Size; dst->Type = src->Type; dst->Format = src->Format; - dst->Stride = src->Stride; dst->StrideB = src->StrideB; dst->Ptr = src->Ptr; - dst->Enabled = src->Enabled; dst->Normalized = src->Normalized; dst->Integer = src->Integer; dst->Doubles = src->Doubles; @@ -2269,13 +2334,13 @@ _mesa_copy_client_array(struct gl_context *ctx, void _mesa_copy_vertex_attrib_array(struct gl_context *ctx, - struct gl_vertex_attrib_array *dst, - const struct gl_vertex_attrib_array *src) + struct gl_array_attributes *dst, + const struct gl_array_attributes *src) { dst->Size = src->Size; dst->Type = src->Type; dst->Format = src->Format; - dst->VertexBinding = src->VertexBinding; + dst->BufferBindingIndex = src->BufferBindingIndex; dst->RelativeOffset = src->RelativeOffset; dst->Format = src->Format; dst->Integer = src->Integer; @@ -2299,55 +2364,43 @@ _mesa_copy_vertex_buffer_binding(struct gl_context *ctx, _mesa_reference_buffer_object(ctx, &dst->BufferObj, src->BufferObj); } -/** - * Print vertex array's fields. - */ -static void -print_array(const char *name, GLint index, const struct gl_client_array *array) -{ - if (index >= 0) - fprintf(stderr, " %s[%d]: ", name, index); - else - fprintf(stderr, " %s: ", name); - 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); -} - - /** * Print current vertex object/array info. For debug. */ void _mesa_print_arrays(struct gl_context *ctx) { - struct gl_vertex_array_object *vao = ctx->Array.VAO; - GLuint i; + const struct gl_vertex_array_object *vao = ctx->Array.VAO; + + fprintf(stderr, "Array Object %u\n", vao->Name); - printf("Array Object %u\n", vao->Name); - if (vao->_VertexAttrib[VERT_ATTRIB_POS].Enabled) - print_array("Vertex", -1, &vao->_VertexAttrib[VERT_ATTRIB_POS]); - if (vao->_VertexAttrib[VERT_ATTRIB_NORMAL].Enabled) - print_array("Normal", -1, &vao->_VertexAttrib[VERT_ATTRIB_NORMAL]); - if (vao->_VertexAttrib[VERT_ATTRIB_COLOR0].Enabled) - print_array("Color", -1, &vao->_VertexAttrib[VERT_ATTRIB_COLOR0]); - for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) - if (vao->_VertexAttrib[VERT_ATTRIB_TEX(i)].Enabled) - print_array("TexCoord", i, &vao->_VertexAttrib[VERT_ATTRIB_TEX(i)]); - for (i = 0; i < VERT_ATTRIB_GENERIC_MAX; i++) - if (vao->_VertexAttrib[VERT_ATTRIB_GENERIC(i)].Enabled) - print_array("Attrib", i, &vao->_VertexAttrib[VERT_ATTRIB_GENERIC(i)]); + unsigned i; + for (i = 0; i < VERT_ATTRIB_MAX; ++i) { + const struct gl_array_attributes *array = &vao->VertexAttrib[i]; + if (!array->Enabled) + continue; + + const struct gl_vertex_buffer_binding *binding = + &vao->BufferBinding[array->BufferBindingIndex]; + const struct gl_buffer_object *bo = binding->BufferObj; + + fprintf(stderr, " %s: Ptr=%p, Type=%s, Size=%d, ElemSize=%u, " + "Stride=%d, Buffer=%u(Size %lu)\n", + gl_vert_attrib_name((gl_vert_attrib)i), + array->Ptr, _mesa_enum_to_string(array->Type), array->Size, + array->_ElementSize, binding->Stride, bo->Name, + (unsigned long) bo->Size); + } } /** * 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 */ @@ -2370,7 +2423,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);