summaryrefslogtreecommitdiffstats
path: root/src/mesa/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/main')
-rw-r--r--src/mesa/main/api_arrayelt.c34
-rw-r--r--src/mesa/main/arrayobj.c21
-rw-r--r--src/mesa/main/draw.c13
-rw-r--r--src/mesa/main/get.c15
-rw-r--r--src/mesa/main/get_hash_params.py20
-rw-r--r--src/mesa/main/mtypes.h27
-rw-r--r--src/mesa/main/varray.c62
-rw-r--r--src/mesa/main/varray.h6
8 files changed, 114 insertions, 84 deletions
diff --git a/src/mesa/main/api_arrayelt.c b/src/mesa/main/api_arrayelt.c
index 25cbc5326f8..2b59c478d9e 100644
--- a/src/mesa/main/api_arrayelt.c
+++ b/src/mesa/main/api_arrayelt.c
@@ -1575,7 +1575,7 @@ _ae_update_state(struct gl_context *ctx)
if (vao->Enabled & VERT_BIT_COLOR_INDEX) {
aa->array = &vao->VertexAttrib[VERT_ATTRIB_COLOR_INDEX];
aa->binding = &vao->BufferBinding[aa->array->BufferBindingIndex];
- aa->offset = IndexFuncs[TYPE_IDX(aa->array->Type)];
+ aa->offset = IndexFuncs[TYPE_IDX(aa->array->Format.Type)];
check_vbo(actx, aa->binding->BufferObj);
aa++;
}
@@ -1591,7 +1591,7 @@ _ae_update_state(struct gl_context *ctx)
if (vao->Enabled & VERT_BIT_NORMAL) {
aa->array = &vao->VertexAttrib[VERT_ATTRIB_NORMAL];
aa->binding = &vao->BufferBinding[aa->array->BufferBindingIndex];
- aa->offset = NormalFuncs[TYPE_IDX(aa->array->Type)];
+ aa->offset = NormalFuncs[TYPE_IDX(aa->array->Format.Type)];
check_vbo(actx, aa->binding->BufferObj);
aa++;
}
@@ -1599,7 +1599,7 @@ _ae_update_state(struct gl_context *ctx)
if (vao->Enabled & VERT_BIT_COLOR0) {
aa->array = &vao->VertexAttrib[VERT_ATTRIB_COLOR0];
aa->binding = &vao->BufferBinding[aa->array->BufferBindingIndex];
- aa->offset = ColorFuncs[aa->array->Size-3][TYPE_IDX(aa->array->Type)];
+ aa->offset = ColorFuncs[aa->array->Format.Size-3][TYPE_IDX(aa->array->Format.Type)];
check_vbo(actx, aa->binding->BufferObj);
aa++;
}
@@ -1607,7 +1607,7 @@ _ae_update_state(struct gl_context *ctx)
if (vao->Enabled & VERT_BIT_COLOR1) {
aa->array = &vao->VertexAttrib[VERT_ATTRIB_COLOR1];
aa->binding = &vao->BufferBinding[aa->array->BufferBindingIndex];
- aa->offset = SecondaryColorFuncs[TYPE_IDX(aa->array->Type)];
+ aa->offset = SecondaryColorFuncs[TYPE_IDX(aa->array->Format.Type)];
check_vbo(actx, aa->binding->BufferObj);
aa++;
}
@@ -1615,7 +1615,7 @@ _ae_update_state(struct gl_context *ctx)
if (vao->Enabled & VERT_BIT_FOG) {
aa->array = &vao->VertexAttrib[VERT_ATTRIB_FOG];
aa->binding = &vao->BufferBinding[aa->array->BufferBindingIndex];
- aa->offset = FogCoordFuncs[TYPE_IDX(aa->array->Type)];
+ aa->offset = FogCoordFuncs[TYPE_IDX(aa->array->Format.Type)];
check_vbo(actx, aa->binding->BufferObj);
aa++;
}
@@ -1629,10 +1629,10 @@ _ae_update_state(struct gl_context *ctx)
*/
at->array = attribArray;
at->binding = &vao->BufferBinding[attribArray->BufferBindingIndex];
- assert(!at->array->Normalized);
- at->func = AttribFuncsNV[at->array->Normalized]
- [at->array->Size-1]
- [TYPE_IDX(at->array->Type)];
+ assert(!at->array->Format.Normalized);
+ at->func = AttribFuncsNV[at->array->Format.Normalized]
+ [at->array->Format.Size-1]
+ [TYPE_IDX(at->array->Format.Type)];
at->index = VERT_ATTRIB_TEX0 + i;
check_vbo(actx, at->binding->BufferObj);
at++;
@@ -1652,18 +1652,18 @@ _ae_update_state(struct gl_context *ctx)
* change from one execution of _ae_ArrayElement() to
* the next. Doing so caused UT to break.
*/
- if (at->array->Doubles)
+ if (at->array->Format.Doubles)
intOrNorm = 3;
- else if (at->array->Integer)
+ else if (at->array->Format.Integer)
intOrNorm = 2;
- else if (at->array->Normalized)
+ else if (at->array->Format.Normalized)
intOrNorm = 1;
else
intOrNorm = 0;
at->func = AttribFuncsARB[intOrNorm]
- [at->array->Size-1]
- [TYPE_IDX(at->array->Type)];
+ [at->array->Format.Size-1]
+ [TYPE_IDX(at->array->Format.Type)];
at->index = i;
check_vbo(actx, at->binding->BufferObj);
@@ -1678,15 +1678,15 @@ _ae_update_state(struct gl_context *ctx)
*/
aa->array = &vao->VertexAttrib[VERT_ATTRIB_GENERIC0];
aa->binding = &vao->BufferBinding[aa->array->BufferBindingIndex];
- assert(aa->array->Size >= 2); /* XXX fix someday? */
- aa->offset = VertexFuncs[aa->array->Size-2][TYPE_IDX(aa->array->Type)];
+ assert(aa->array->Format.Size >= 2); /* XXX fix someday? */
+ aa->offset = VertexFuncs[aa->array->Format.Size-2][TYPE_IDX(aa->array->Format.Type)];
check_vbo(actx, aa->binding->BufferObj);
aa++;
}
else if (vao->Enabled & VERT_BIT_POS) {
aa->array = &vao->VertexAttrib[VERT_ATTRIB_POS];
aa->binding = &vao->BufferBinding[aa->array->BufferBindingIndex];
- aa->offset = VertexFuncs[aa->array->Size-2][TYPE_IDX(aa->array->Type)];
+ aa->offset = VertexFuncs[aa->array->Format.Size-2][TYPE_IDX(aa->array->Format.Type)];
check_vbo(actx, aa->binding->BufferObj);
aa++;
}
diff --git a/src/mesa/main/arrayobj.c b/src/mesa/main/arrayobj.c
index f80bf2c949c..bfd6fce6798 100644
--- a/src/mesa/main/arrayobj.c
+++ b/src/mesa/main/arrayobj.c
@@ -385,22 +385,17 @@ init_array(struct gl_context *ctx,
assert(index < ARRAY_SIZE(vao->BufferBinding));
struct gl_vertex_buffer_binding *binding = &vao->BufferBinding[index];
- array->Size = size;
- array->Type = type;
- array->Format = GL_RGBA; /* only significant for GL_EXT_vertex_array_bgra */
+ _mesa_set_vertex_format(&array->Format, size, type, GL_RGBA,
+ GL_FALSE, GL_FALSE, GL_FALSE);
array->Stride = 0;
array->Ptr = NULL;
array->RelativeOffset = 0;
- array->Normalized = GL_FALSE;
- array->Integer = GL_FALSE;
- array->Doubles = GL_FALSE;
- array->_ElementSize = size * _mesa_sizeof_type(type);
ASSERT_BITFIELD_SIZE(struct gl_array_attributes, BufferBindingIndex,
VERT_ATTRIB_MAX - 1);
array->BufferBindingIndex = index;
binding->Offset = 0;
- binding->Stride = array->_ElementSize;
+ binding->Stride = array->Format._ElementSize;
binding->BufferObj = NULL;
binding->_BoundArrays = BITFIELD_BIT(index);
@@ -756,7 +751,7 @@ _mesa_update_vao_derived_arrays(struct gl_context *ctx,
GLbitfield eff_bound_arrays = bound;
const GLubyte *ptr = attrib->Ptr;
- unsigned vertex_end = attrib->_ElementSize;
+ unsigned vertex_end = attrib->Format._ElementSize;
/* Walk other user space arrays and see which are interleaved
* using the same binding parameters.
@@ -778,9 +773,10 @@ _mesa_update_vao_derived_arrays(struct gl_context *ctx,
if (binding->InstanceDivisor != binding2->InstanceDivisor)
continue;
if (ptr <= attrib2->Ptr) {
- if (ptr + binding->Stride < attrib2->Ptr + attrib2->_ElementSize)
+ if (ptr + binding->Stride < attrib2->Ptr +
+ attrib2->Format._ElementSize)
continue;
- unsigned end = attrib2->Ptr + attrib2->_ElementSize - ptr;
+ unsigned end = attrib2->Ptr + attrib2->Format._ElementSize - ptr;
vertex_end = MAX2(vertex_end, end);
} else {
if (attrib2->Ptr + binding->Stride < ptr + vertex_end)
@@ -823,7 +819,8 @@ _mesa_update_vao_derived_arrays(struct gl_context *ctx,
/* Query the original api defined attrib/binding information ... */
const unsigned char *const map =_mesa_vao_attribute_map[mode];
if (vao->Enabled & VERT_BIT(map[attr])) {
- const struct gl_array_attributes *attrib = &vao->VertexAttrib[map[attr]];
+ const struct gl_array_attributes *attrib =
+ &vao->VertexAttrib[map[attr]];
const struct gl_vertex_buffer_binding *binding =
&vao->BufferBinding[attrib->BufferBindingIndex];
/* ... and compare that with the computed attrib/binding */
diff --git a/src/mesa/main/draw.c b/src/mesa/main/draw.c
index 313df6aa8bc..bfc4b9c9373 100644
--- a/src/mesa/main/draw.c
+++ b/src/mesa/main/draw.c
@@ -82,18 +82,19 @@ check_array_data(struct gl_context *ctx, struct gl_vertex_array_object *vao,
data = ADD_POINTERS(_mesa_vertex_attrib_address(array, binding),
bo->Mappings[MAP_INTERNAL].Pointer);
}
- switch (array->Type) {
+ switch (array->Format.Type) {
case GL_FLOAT:
{
GLfloat *f = (GLfloat *) ((GLubyte *) data + binding->Stride * j);
GLint k;
- for (k = 0; k < array->Size; k++) {
+ for (k = 0; k < array->Format.Size; k++) {
if (IS_INF_OR_NAN(f[k]) || f[k] >= 1.0e20F || f[k] <= -1.0e10F) {
printf("Bad array data:\n");
printf(" Element[%u].%u = %f\n", j, k, f[k]);
printf(" Array %u at %p\n", attrib, (void *) array);
printf(" Type 0x%x, Size %d, Stride %d\n",
- array->Type, array->Size, binding->Stride);
+ array->Format.Type, array->Format.Size,
+ binding->Stride);
printf(" Address/offset %p in Buffer Object %u\n",
array->Ptr, bo->Name);
f[k] = 1.0F; /* XXX replace the bad value! */
@@ -288,7 +289,7 @@ print_draw_arrays(struct gl_context *ctx,
printf("attr %s: size %d stride %d "
"ptr %p Bufobj %u\n",
gl_vert_attrib_name((gl_vert_attrib) i),
- array->Size, binding->Stride,
+ array->Format.Size, binding->Stride,
array->Ptr, bufObj->Name);
if (_mesa_is_bufferobj(bufObj)) {
@@ -299,7 +300,7 @@ print_draw_arrays(struct gl_context *ctx,
_mesa_vertex_attrib_address(array, binding);
unsigned multiplier;
- switch (array->Type) {
+ switch (array->Format.Type) {
case GL_DOUBLE:
case GL_INT64_ARB:
case GL_UNSIGNED_INT64_ARB:
@@ -313,7 +314,7 @@ print_draw_arrays(struct gl_context *ctx,
int *k = (int *) f;
int i = 0;
int n = (count - 1) * (binding->Stride / (4 * multiplier))
- + array->Size;
+ + array->Format.Size;
if (n > 32)
n = 32;
printf(" Data at offset %d:\n", offset);
diff --git a/src/mesa/main/get.c b/src/mesa/main/get.c
index ac17539f094..ee77c45d03c 100644
--- a/src/mesa/main/get.c
+++ b/src/mesa/main/get.c
@@ -755,13 +755,22 @@ find_custom_value(struct gl_context *ctx, const struct value_desc *d, union valu
v->value_bool = !!(ctx->Array.VAO->Enabled & VERT_BIT_POINT_SIZE);
break;
- case GL_TEXTURE_COORD_ARRAY_SIZE:
case GL_TEXTURE_COORD_ARRAY_TYPE:
case GL_TEXTURE_COORD_ARRAY_STRIDE:
array = &ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)];
v->value_int = *(GLuint *) ((char *) array + d->offset);
break;
+ case GL_TEXTURE_COORD_ARRAY_SIZE:
+ array = &ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_TEX(ctx->Array.ActiveTexture)];
+ v->value_int = array->Format.Size;
+ break;
+
+ case GL_VERTEX_ARRAY_SIZE:
+ array = &ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_POS];
+ v->value_int = array->Format.Size;
+ break;
+
case GL_ACTIVE_TEXTURE_ARB:
v->value_int = GL_TEXTURE0_ARB + ctx->Texture.CurrentUnit;
break;
@@ -969,11 +978,11 @@ find_custom_value(struct gl_context *ctx, const struct value_desc *d, union valu
/* ARB_vertex_array_bgra */
case GL_COLOR_ARRAY_SIZE:
array = &ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_COLOR0];
- v->value_int = array->Format == GL_BGRA ? GL_BGRA : array->Size;
+ v->value_int = array->Format.Format == GL_BGRA ? GL_BGRA : array->Format.Size;
break;
case GL_SECONDARY_COLOR_ARRAY_SIZE:
array = &ctx->Array.VAO->VertexAttrib[VERT_ATTRIB_COLOR1];
- v->value_int = array->Format == GL_BGRA ? GL_BGRA : array->Size;
+ v->value_int = array->Format.Format == GL_BGRA ? GL_BGRA : array->Format.Size;
break;
/* ARB_copy_buffer */
diff --git a/src/mesa/main/get_hash_params.py b/src/mesa/main/get_hash_params.py
index ec5eef5f194..0b8ec9ea0bb 100644
--- a/src/mesa/main/get_hash_params.py
+++ b/src/mesa/main/get_hash_params.py
@@ -212,19 +212,19 @@ descriptor=[
[ "TEXTURE_MATRIX", "LOC_CUSTOM, TYPE_MATRIX, 0, extra_valid_texture_unit" ],
[ "TEXTURE_STACK_DEPTH", "LOC_CUSTOM, TYPE_INT, 0, extra_valid_texture_unit" ],
[ "VERTEX_ARRAY", "LOC_CUSTOM, TYPE_BOOLEAN, 0, NO_EXTRA" ],
- [ "VERTEX_ARRAY_SIZE", "ARRAY_UBYTE(VertexAttrib[VERT_ATTRIB_POS].Size), NO_EXTRA" ],
- [ "VERTEX_ARRAY_TYPE", "ARRAY_ENUM16(VertexAttrib[VERT_ATTRIB_POS].Type), NO_EXTRA" ],
+ [ "VERTEX_ARRAY_SIZE", "LOC_CUSTOM, TYPE_INT, 0, NO_EXTRA" ],
+ [ "VERTEX_ARRAY_TYPE", "ARRAY_ENUM16(VertexAttrib[VERT_ATTRIB_POS].Format.Type), NO_EXTRA" ],
[ "VERTEX_ARRAY_STRIDE", "ARRAY_SHORT(VertexAttrib[VERT_ATTRIB_POS].Stride), NO_EXTRA" ],
[ "NORMAL_ARRAY", "LOC_CUSTOM, TYPE_BOOLEAN, 0, NO_EXTRA" ],
- [ "NORMAL_ARRAY_TYPE", "ARRAY_ENUM16(VertexAttrib[VERT_ATTRIB_NORMAL].Type), NO_EXTRA" ],
+ [ "NORMAL_ARRAY_TYPE", "ARRAY_ENUM16(VertexAttrib[VERT_ATTRIB_NORMAL].Format.Type), NO_EXTRA" ],
[ "NORMAL_ARRAY_STRIDE", "ARRAY_SHORT(VertexAttrib[VERT_ATTRIB_NORMAL].Stride), NO_EXTRA" ],
[ "COLOR_ARRAY", "LOC_CUSTOM, TYPE_BOOLEAN, 0, NO_EXTRA" ],
[ "COLOR_ARRAY_SIZE", "LOC_CUSTOM, TYPE_INT, 0, NO_EXTRA" ],
- [ "COLOR_ARRAY_TYPE", "ARRAY_ENUM16(VertexAttrib[VERT_ATTRIB_COLOR0].Type), NO_EXTRA" ],
+ [ "COLOR_ARRAY_TYPE", "ARRAY_ENUM16(VertexAttrib[VERT_ATTRIB_COLOR0].Format.Type), NO_EXTRA" ],
[ "COLOR_ARRAY_STRIDE", "ARRAY_SHORT(VertexAttrib[VERT_ATTRIB_COLOR0].Stride), NO_EXTRA" ],
[ "TEXTURE_COORD_ARRAY", "LOC_CUSTOM, TYPE_BOOLEAN, 0, NO_EXTRA" ],
- [ "TEXTURE_COORD_ARRAY_SIZE", "LOC_CUSTOM, TYPE_UBYTE, offsetof(struct gl_array_attributes, Size), NO_EXTRA" ],
- [ "TEXTURE_COORD_ARRAY_TYPE", "LOC_CUSTOM, TYPE_ENUM16, offsetof(struct gl_array_attributes, Type), NO_EXTRA" ],
+ [ "TEXTURE_COORD_ARRAY_SIZE", "LOC_CUSTOM, TYPE_INT, 0, NO_EXTRA" ],
+ [ "TEXTURE_COORD_ARRAY_TYPE", "LOC_CUSTOM, TYPE_ENUM16, offsetof(struct gl_array_attributes, Format.Type), NO_EXTRA" ],
[ "TEXTURE_COORD_ARRAY_STRIDE", "LOC_CUSTOM, TYPE_SHORT, offsetof(struct gl_array_attributes, Stride), NO_EXTRA" ],
# GL_ARB_multitexture
@@ -254,7 +254,7 @@ descriptor=[
{ "apis": ["GLES"], "params": [
# OES_point_size_array
[ "POINT_SIZE_ARRAY_OES", "LOC_CUSTOM, TYPE_BOOLEAN, 0, NO_EXTRA" ],
- [ "POINT_SIZE_ARRAY_TYPE_OES", "ARRAY_FIELD(VertexAttrib[VERT_ATTRIB_POINT_SIZE].Type, TYPE_ENUM16), NO_EXTRA" ],
+ [ "POINT_SIZE_ARRAY_TYPE_OES", "ARRAY_FIELD(VertexAttrib[VERT_ATTRIB_POINT_SIZE].Format.Type, TYPE_ENUM16), NO_EXTRA" ],
[ "POINT_SIZE_ARRAY_STRIDE_OES", "ARRAY_FIELD(VertexAttrib[VERT_ATTRIB_POINT_SIZE].Stride, TYPE_SHORT), NO_EXTRA" ],
[ "POINT_SIZE_ARRAY_BUFFER_BINDING_OES", "LOC_CUSTOM, TYPE_INT, 0, NO_EXTRA" ],
]},
@@ -794,7 +794,7 @@ descriptor=[
[ "NORMAL_ARRAY_COUNT_EXT", "CONST(0), NO_EXTRA" ],
[ "COLOR_ARRAY_COUNT_EXT", "CONST(0), NO_EXTRA" ],
[ "INDEX_ARRAY", "LOC_CUSTOM, TYPE_BOOLEAN, 0, NO_EXTRA" ],
- [ "INDEX_ARRAY_TYPE", "ARRAY_ENUM16(VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Type), NO_EXTRA" ],
+ [ "INDEX_ARRAY_TYPE", "ARRAY_ENUM16(VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Format.Type), NO_EXTRA" ],
[ "INDEX_ARRAY_STRIDE", "ARRAY_SHORT(VertexAttrib[VERT_ATTRIB_COLOR_INDEX].Stride), NO_EXTRA" ],
[ "INDEX_ARRAY_COUNT_EXT", "CONST(0), NO_EXTRA" ],
[ "TEXTURE_COORD_ARRAY_COUNT_EXT", "CONST(0), NO_EXTRA" ],
@@ -828,14 +828,14 @@ descriptor=[
[ "COLOR_SUM", "CONTEXT_BOOL(Fog.ColorSumEnabled), NO_EXTRA" ],
[ "CURRENT_SECONDARY_COLOR", "CONTEXT_FIELD(Current.Attrib[VERT_ATTRIB_COLOR1][0], TYPE_FLOATN_4), extra_flush_current" ],
[ "SECONDARY_COLOR_ARRAY", "LOC_CUSTOM, TYPE_BOOLEAN, 0, NO_EXTRA" ],
- [ "SECONDARY_COLOR_ARRAY_TYPE", "ARRAY_ENUM16(VertexAttrib[VERT_ATTRIB_COLOR1].Type), NO_EXTRA" ],
+ [ "SECONDARY_COLOR_ARRAY_TYPE", "ARRAY_ENUM16(VertexAttrib[VERT_ATTRIB_COLOR1].Format.Type), NO_EXTRA" ],
[ "SECONDARY_COLOR_ARRAY_STRIDE", "ARRAY_SHORT(VertexAttrib[VERT_ATTRIB_COLOR1].Stride), NO_EXTRA" ],
[ "SECONDARY_COLOR_ARRAY_SIZE", "LOC_CUSTOM, TYPE_INT, 0, NO_EXTRA" ],
# GL_EXT_fog_coord
[ "CURRENT_FOG_COORDINATE", "CONTEXT_FLOAT(Current.Attrib[VERT_ATTRIB_FOG][0]), extra_flush_current" ],
[ "FOG_COORDINATE_ARRAY", "LOC_CUSTOM, TYPE_BOOLEAN, 0, NO_EXTRA" ],
- [ "FOG_COORDINATE_ARRAY_TYPE", "ARRAY_ENUM16(VertexAttrib[VERT_ATTRIB_FOG].Type), NO_EXTRA" ],
+ [ "FOG_COORDINATE_ARRAY_TYPE", "ARRAY_ENUM16(VertexAttrib[VERT_ATTRIB_FOG].Format.Type), NO_EXTRA" ],
[ "FOG_COORDINATE_ARRAY_STRIDE", "ARRAY_SHORT(VertexAttrib[VERT_ATTRIB_FOG].Stride), NO_EXTRA" ],
[ "FOG_COORDINATE_SOURCE", "CONTEXT_ENUM16(Fog.FogCoordinateSource), NO_EXTRA" ],
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index da6a2616881..62d3b75a366 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -457,6 +457,21 @@ struct gl_colorbuffer_attrib
/**
+ * Vertex format to describe a vertex element.
+ */
+struct gl_vertex_format
+{
+ GLenum16 Type; /**< datatype: GL_FLOAT, GL_INT, etc */
+ GLenum16 Format; /**< default: GL_RGBA, but may be GL_BGRA */
+ GLubyte Size:5; /**< components per element (1,2,3,4) */
+ GLubyte Normalized:1; /**< GL_ARB_vertex_program */
+ GLubyte Integer:1; /**< Integer-valued? */
+ GLubyte Doubles:1; /**< double values are not converted to floats */
+ GLubyte _ElementSize; /**< Size of each element in bytes */
+};
+
+
+/**
* Current attribute group (GL_CURRENT_BIT).
*/
struct gl_current_attrib
@@ -1419,14 +1434,10 @@ struct gl_array_attributes
const GLubyte *Ptr;
/** Offset of the first element relative to the binding offset */
GLuint RelativeOffset;
- GLshort Stride; /**< Stride as specified with gl*Pointer() */
- GLenum16 Type; /**< Datatype: GL_FLOAT, GL_INT, etc */
- GLenum16 Format; /**< Default: GL_RGBA, but may be GL_BGRA */
- GLubyte Size; /**< Components per element (1,2,3,4) */
- unsigned Normalized:1; /**< Fixed-point values are normalized when converted to floats */
- unsigned Integer:1; /**< Fixed-point values are not converted to floats */
- unsigned Doubles:1; /**< double precision values are not converted to floats */
- unsigned _ElementSize:8; /**< Size of each element in bytes */
+ /** Vertex format */
+ struct gl_vertex_format Format;
+ /** Stride as specified with gl*Pointer() */
+ GLshort Stride;
/** Index into gl_vertex_array_object::BufferBinding[] array */
unsigned BufferBindingIndex:6;
diff --git a/src/mesa/main/varray.c b/src/mesa/main/varray.c
index a6d00c6ef9c..5af5a7f773f 100644
--- a/src/mesa/main/varray.c
+++ b/src/mesa/main/varray.c
@@ -33,6 +33,7 @@
#include "context.h"
#include "enable.h"
#include "enums.h"
+#include "glformats.h"
#include "hash.h"
#include "image.h"
#include "macros.h"
@@ -243,6 +244,24 @@ vertex_binding_divisor(struct gl_context *ctx,
}
+void
+_mesa_set_vertex_format(struct gl_vertex_format *vertex_format,
+ GLubyte size, GLenum16 type, GLenum16 format,
+ GLboolean normalized, GLboolean integer,
+ GLboolean doubles)
+{
+ assert(size <= 4);
+ vertex_format->Type = type;
+ vertex_format->Format = format;
+ vertex_format->Size = size;
+ vertex_format->Normalized = normalized;
+ vertex_format->Integer = integer;
+ vertex_format->Doubles = doubles;
+ vertex_format->_ElementSize = _mesa_bytes_per_vertex_attrib(size, type);
+ assert(vertex_format->_ElementSize <= 4*sizeof(double));
+}
+
+
/**
* Examine the API profile and extensions to determine which types are legal
* for vertex arrays. This is called once from update_array_format().
@@ -330,22 +349,13 @@ _mesa_update_array_format(struct gl_context *ctx,
GLuint relativeOffset)
{
struct gl_array_attributes *const array = &vao->VertexAttrib[attrib];
- GLint elementSize;
assert(!vao->SharedAndImmutable);
assert(size <= 4);
- 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;
+ _mesa_set_vertex_format(&array->Format, size, type, format,
+ normalized, integer, doubles);
vao->NewArrays |= vao->Enabled & VERT_BIT(attrib);
if (vao == ctx->Array.VAO)
@@ -609,7 +619,8 @@ update_array(struct gl_context *ctx,
array->Ptr = ptr;
/* Update the vertex buffer binding */
- GLsizei effectiveStride = stride != 0 ? stride : array->_ElementSize;
+ GLsizei effectiveStride = stride != 0 ?
+ stride : array->Format._ElementSize;
_mesa_bind_vertex_buffer(ctx, vao, attrib,
ctx->Array.ArrayBufferObj, (GLintptr) ptr,
effectiveStride);
@@ -1269,25 +1280,25 @@ get_vertex_array_attrib(struct gl_context *ctx,
case GL_VERTEX_ATTRIB_ARRAY_ENABLED_ARB:
return !!(vao->Enabled & VERT_BIT_GENERIC(index));
case GL_VERTEX_ATTRIB_ARRAY_SIZE_ARB:
- return (array->Format == GL_BGRA) ? GL_BGRA : array->Size;
+ return (array->Format.Format == GL_BGRA) ? GL_BGRA : array->Format.Size;
case GL_VERTEX_ATTRIB_ARRAY_STRIDE_ARB:
return array->Stride;
case GL_VERTEX_ATTRIB_ARRAY_TYPE_ARB:
- return array->Type;
+ return array->Format.Type;
case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED_ARB:
- return array->Normalized;
+ return array->Format.Normalized;
case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING_ARB:
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))
|| _mesa_is_gles3(ctx)) {
- return array->Integer;
+ return array->Format.Integer;
}
goto error;
case GL_VERTEX_ATTRIB_ARRAY_LONG:
if (_mesa_is_desktop_gl(ctx)) {
- return array->Doubles;
+ return array->Format.Doubles;
}
goto error;
case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ARB:
@@ -2771,17 +2782,11 @@ _mesa_copy_vertex_attrib_array(struct gl_context *ctx,
struct gl_array_attributes *dst,
const struct gl_array_attributes *src)
{
- dst->Size = src->Size;
- dst->Type = src->Type;
- dst->Format = src->Format;
- dst->BufferBindingIndex = src->BufferBindingIndex;
+ dst->Ptr = src->Ptr;
dst->RelativeOffset = src->RelativeOffset;
dst->Format = src->Format;
- dst->Integer = src->Integer;
- dst->Doubles = src->Doubles;
- dst->Normalized = src->Normalized;
- dst->Ptr = src->Ptr;
- dst->_ElementSize = src->_ElementSize;
+ dst->Stride = src->Stride;
+ dst->BufferBindingIndex = src->BufferBindingIndex;
dst->_EffBufferBindingIndex = src->_EffBufferBindingIndex;
dst->_EffRelativeOffset = src->_EffRelativeOffset;
}
@@ -2823,8 +2828,9 @@ _mesa_print_arrays(struct gl_context *ctx)
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,
+ array->Ptr, _mesa_enum_to_string(array->Format.Type),
+ array->Format.Size,
+ array->Format._ElementSize, binding->Stride, bo->Name,
(unsigned long) bo->Size);
}
}
diff --git a/src/mesa/main/varray.h b/src/mesa/main/varray.h
index 823e4f408b1..0be57971bd7 100644
--- a/src/mesa/main/varray.h
+++ b/src/mesa/main/varray.h
@@ -29,6 +29,12 @@
#include "bufferobj.h"
+void
+_mesa_set_vertex_format(struct gl_vertex_format *vertex_format,
+ GLubyte size, GLenum16 type, GLenum16 format,
+ GLboolean normalized, GLboolean integer,
+ GLboolean doubles);
+
/**
* Returns a pointer to the vertex attribute data in a client array,