if (index_buffer == NULL)
return;
- ib_type_size = index_buffer->index_size;
+ ib_type_size = 1 << index_buffer->index_size_shift;
ib_size = index_buffer->count ? ib_type_size * index_buffer->count :
index_buffer->obj->Size;
bufferobj = index_buffer->obj;
if (brw->ib.bo != old_bo)
brw->ctx.NewDriverState |= BRW_NEW_INDEX_BUFFER;
- if (index_buffer->index_size != brw->ib.index_size) {
- brw->ib.index_size = index_buffer->index_size;
+ unsigned index_size = 1 << index_buffer->index_size_shift;
+ if (index_size != brw->ib.index_size) {
+ brw->ib.index_size = index_size;
brw->ctx.NewDriverState |= BRW_NEW_INDEX_BUFFER;
}
bool cut_index_will_work;
- switch (ib->index_size) {
- case 1:
+ switch (ib->index_size_shift) {
+ case 0:
cut_index_will_work = ctx->Array.RestartIndex == 0xff;
break;
- case 2:
+ case 1:
cut_index_will_work = ctx->Array.RestartIndex == 0xffff;
break;
- case 4:
+ case 2:
cut_index_will_work = ctx->Array.RestartIndex == 0xffffffff;
break;
default:
assert(brw->ib.enable_cut_index == brw->prim_restart.enable_cut_index);
ib.CutIndexEnable = brw->ib.enable_cut_index;
#endif
- ib.IndexFormat = brw_get_index_type(index_buffer->index_size);
+ ib.IndexFormat = brw_get_index_type(1 << index_buffer->index_size_shift);
/* The VF cache designers apparently cut corners, and made the cache
* only consider the bottom 32 bits of memory addresses. If you happen
unsigned max_out;
if (ib) {
- switch (ib->index_size) {
- case 4:
+ switch (ib->index_size_shift) {
+ case 2:
max_out = MAX_OUT_I32;
break;
- case 2:
+ case 1:
max_out = MAX_OUT_I16;
break;
- case 1:
+ case 0:
max_out = MAX_OUT_I16;
break;
if (ib) {
GLenum ib_type;
- if (ib->index_size == 4)
+ if (ib->index_size_shift == 2)
ib_type = GL_UNSIGNED_INT;
- else if (ib->index_size == 2)
+ else if (ib->index_size_shift == 1)
ib_type = GL_UNSIGNED_SHORT;
else
ib_type = GL_UNSIGNED_BYTE;
{
switch (type) {
case GL_UNSIGNED_INT:
- ib->index_size = 4;
ib->index_size_shift = 2;
break;
case GL_UNSIGNED_SHORT:
- ib->index_size = 2;
ib->index_size_shift = 1;
break;
case GL_UNSIGNED_BYTE:
- ib->index_size = 1;
ib->index_size_shift = 0;
break;
default:
assert(!"unsupported index data type");
/* In case assert is turned off */
- ib->index_size = 1;
ib->index_size_shift = 0;
break;
}
struct _mesa_index_buffer
{
GLuint count;
- uint8_t index_size;
uint8_t index_size_shift; /* logbase2(index_size) */
struct gl_buffer_object *obj;
const void *ptr;
nr_prims);
}
- info.index_size = ib->index_size;
+ info.index_size = 1 << ib->index_size_shift;
info.min_index = min_index;
info.max_index = max_index;
/* indices are always in a real VBO */
assert(_mesa_is_bufferobj(bufobj));
- info.index_size = ib->index_size;
+ info.index_size = 1 << ib->index_size_shift;
info.index.resource = st_buffer_object(bufobj)->buffer;
info.start = pointer_to_offset(ib->ptr) >> ib->index_size_shift;
if (ib) {
struct gl_buffer_object *bufobj = ib->obj;
- unsigned index_size = ib->index_size;
+ unsigned index_size = 1 << ib->index_size_shift;
if (index_size == 0)
goto out_unref_vertex;
bo[*nr_bo] = ib->obj;
(*nr_bo)++;
ptr = ctx->Driver.MapBufferRange(ctx, (GLsizeiptr) ib->ptr,
- ib->count * ib->index_size,
+ ib->count << ib->index_size_shift,
GL_MAP_READ_BIT, ib->obj,
MAP_INTERNAL);
assert(ib->obj->Mappings[MAP_INTERNAL].Pointer);
ptr = ADD_POINTERS(ib->obj->Mappings[MAP_INTERNAL].Pointer, ib->ptr);
}
- if (ib->index_size == 4 && VB->Primitive[0].basevertex == 0) {
+ if (ib->index_size_shift == 2 && VB->Primitive[0].basevertex == 0) {
VB->Elts = (GLuint *) ptr;
}
else {
GLuint *elts = (GLuint *)get_space(ctx, ib->count * sizeof(GLuint));
VB->Elts = elts;
- if (ib->index_size == 4) {
+ if (ib->index_size_shift == 2) {
const GLuint *in = (GLuint *)ptr;
for (i = 0; i < ib->count; i++)
*elts++ = (GLuint)(*in++) + VB->Primitive[0].basevertex;
}
- else if (ib->index_size == 2) {
+ else if (ib->index_size_shift == 1) {
const GLushort *in = (GLushort *)ptr;
for (i = 0; i < ib->count; i++)
*elts++ = (GLuint)(*in++) + VB->Primitive[0].basevertex;
/* Some users might prefer it if we translated elements to
* GLuints here. Others wouldn't...
*/
- switch (ib->index_size) {
- case 4:
+ switch (ib->index_size_shift) {
+ case 2:
tmp_indices = rebase_GLuint( ptr, ib->count, min_index );
break;
- case 2:
+ case 1:
tmp_indices = rebase_GLushort( ptr, ib->count, min_index );
break;
- case 1:
+ case 0:
tmp_indices = rebase_GLubyte( ptr, ib->count, min_index );
break;
}
tmp_ib.obj = ctx->Shared->NullBufferObj;
tmp_ib.ptr = tmp_indices;
tmp_ib.count = ib->count;
- tmp_ib.index_size = ib->index_size;
tmp_ib.index_size_shift = ib->index_size_shift;
ib = &tmp_ib;
ADD_POINTERS(copy->ib->obj->Mappings[MAP_INTERNAL].Pointer,
copy->ib->ptr);
- switch (copy->ib->index_size) {
- case 1:
+ switch (copy->ib->index_size_shift) {
+ case 0:
copy->translated_elt_buf = malloc(sizeof(GLuint) * copy->ib->count);
copy->srcelt = copy->translated_elt_buf;
copy->translated_elt_buf[i] = ((const GLubyte *)srcptr)[i];
break;
- case 2:
+ case 1:
copy->translated_elt_buf = malloc(sizeof(GLuint) * copy->ib->count);
copy->srcelt = copy->translated_elt_buf;
copy->translated_elt_buf[i] = ((const GLushort *)srcptr)[i];
break;
- case 4:
+ case 2:
copy->translated_elt_buf = NULL;
copy->srcelt = (const GLuint *)srcptr;
break;
* list:
*/
copy->dstib.count = 0; /* duplicates dstelt_nr */
- copy->dstib.index_size = 4;
copy->dstib.index_size_shift = 2;
copy->dstib.obj = ctx->Shared->NullBufferObj;
copy->dstib.ptr = copy->dstelt;
ib.count = split->max_index - split->min_index + 1;
ib.ptr = (const void *)((const char *)ib.ptr +
- split->min_index * ib.index_size);
+ (split->min_index << ib.index_size_shift));
/* Rebase the primitives to save index buffer entries. */
for (i = 0; i < split->dstprim_nr; i++)
elts[j] = prim->start + j;
ib.count = count;
- ib.index_size = 4;
ib.index_size_shift = 2;
ib.obj = split->ctx->Shared->NullBufferObj;
ib.ptr = elts;
{
const GLboolean restart = ctx->Array._PrimitiveRestart;
const GLuint restartIndex =
- _mesa_primitive_restart_index(ctx, ib->index_size);
+ _mesa_primitive_restart_index(ctx, 1 << ib->index_size_shift);
const char *indices;
GLuint i;
GLintptr offset = 0;
if (_mesa_is_bufferobj(ib->obj)) {
GLsizeiptr size = MIN2(count << ib->index_size_shift, ib->obj->Size);
- if (vbo_get_minmax_cached(ib->obj, ib->index_size, (GLintptr) indices,
+ if (vbo_get_minmax_cached(ib->obj, 1 << ib->index_size_shift, (GLintptr) indices,
count, min_index, max_index))
return;
MAP_INTERNAL);
}
- switch (ib->index_size) {
- case 4: {
+ switch (ib->index_size_shift) {
+ case 2: {
const GLuint *ui_indices = (const GLuint *)indices;
GLuint max_ui = 0;
GLuint min_ui = ~0U;
*max_index = max_ui;
break;
}
- case 2: {
+ case 1: {
const GLushort *us_indices = (const GLushort *)indices;
GLuint max_us = 0;
GLuint min_us = ~0U;
*max_index = max_us;
break;
}
- case 1: {
+ case 0: {
const GLubyte *ub_indices = (const GLubyte *)indices;
GLuint max_ub = 0;
GLuint min_ub = ~0U;
}
if (_mesa_is_bufferobj(ib->obj)) {
- vbo_minmax_cache_store(ctx, ib->obj, ib->index_size, offset,
+ vbo_minmax_cache_store(ctx, ib->obj, 1 << ib->index_size_shift, offset,
count, *min_index, *max_index);
ctx->Driver.UnmapBuffer(ctx, ib->obj, MAP_INTERNAL);
}
GLuint sub_prim_num;
GLuint end_index;
GLuint sub_end_index;
- GLuint restart_index = _mesa_primitive_restart_index(ctx, ib->index_size);
+ GLuint restart_index = _mesa_primitive_restart_index(ctx, 1 << ib->index_size_shift);
struct _mesa_prim temp_prim;
GLboolean map_ib = ib->obj->Name && !ib->obj->Mappings[MAP_INTERNAL].Pointer;
void *ptr;
ptr = ADD_POINTERS(ib->obj->Mappings[MAP_INTERNAL].Pointer, ib->ptr);
- sub_prims = find_sub_primitives(ptr, ib->index_size,
+ sub_prims = find_sub_primitives(ptr, 1 << ib->index_size_shift,
0, ib->count, restart_index,
&num_sub_prims);