**************************************************************************/
#include <stdio.h>
+#include "main/arrayobj.h"
#include "main/glheader.h"
#include "main/context.h"
#include "main/state.h"
#include "vbo_context.h"
-/**
- * All vertex buffers should be in an unmapped state when we're about
- * to draw.
- */
-static bool
-check_input_buffers_are_unmapped(const struct gl_client_array **inputs)
-{
- GLuint i;
-
- for (i = 0; i < VERT_ATTRIB_MAX; i++) {
- if (inputs[i]) {
- struct gl_buffer_object *obj = inputs[i]->BufferObj;
- if (_mesa_check_disallowed_mapping(obj))
- return false;
- }
- }
-
- return true;
-}
-
-
-/**
- * A debug function that may be called from other parts of Mesa as
- * needed during debugging.
- */
-static bool
-check_buffers_are_unmapped(struct gl_context *ctx)
-{
- struct vbo_context *vbo = vbo_context(ctx);
- struct vbo_exec_context *exec = &vbo->exec;
-
- /* check the current vertex arrays */
- return !_mesa_check_disallowed_mapping(exec->vtx.bufferobj) &&
- check_input_buffers_are_unmapped(exec->array.inputs);
-}
-
-
/**
* Check that element 'j' of the array has reasonable data.
* Map VBO if needed.
* For debugging purposes; not normally used.
*/
static void
-check_array_data(struct gl_context *ctx, struct gl_client_array *array,
+check_array_data(struct gl_context *ctx, struct gl_vertex_array_object *vao,
GLuint attrib, GLuint j)
{
+ const struct gl_array_attributes *array = &vao->VertexAttrib[attrib];
if (array->Enabled) {
+ const struct gl_vertex_buffer_binding *binding =
+ &vao->VertexBinding[array->BufferBindingIndex];
+ struct gl_buffer_object *bo = binding->BufferObj;
const void *data = array->Ptr;
- if (_mesa_is_bufferobj(array->BufferObj)) {
- if (!array->BufferObj->Mappings[MAP_INTERNAL].Pointer) {
+ if (_mesa_is_bufferobj(bo)) {
+ if (!bo->Mappings[MAP_INTERNAL].Pointer) {
/* need to map now */
- array->BufferObj->Mappings[MAP_INTERNAL].Pointer =
- ctx->Driver.MapBufferRange(ctx, 0, array->BufferObj->Size,
- GL_MAP_READ_BIT, array->BufferObj,
+ bo->Mappings[MAP_INTERNAL].Pointer =
+ ctx->Driver.MapBufferRange(ctx, 0, bo->Size,
+ GL_MAP_READ_BIT, bo,
MAP_INTERNAL);
}
- data = ADD_POINTERS(data,
- array->BufferObj->Mappings[MAP_INTERNAL].Pointer);
+ data = ADD_POINTERS(_mesa_vertex_attrib_address(array, binding),
+ bo->Mappings[MAP_INTERNAL].Pointer);
}
switch (array->Type) {
case GL_FLOAT:
{
- GLfloat *f = (GLfloat *) ((GLubyte *) data + array->StrideB * j);
+ GLfloat *f = (GLfloat *) ((GLubyte *) data + binding->Stride * j);
GLint k;
for (k = 0; k < array->Size; k++) {
if (IS_INF_OR_NAN(f[k]) ||
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, array->Stride);
+ array->Type, array->Size, binding->Stride);
printf(" Address/offset %p in Buffer Object %u\n",
- array->Ptr, array->BufferObj->Name);
+ array->Ptr, bo->Name);
f[k] = 1.0F; /* XXX replace the bad value! */
}
/*assert(!IS_INF_OR_NAN(f[k]));*/
* Unmap the buffer object referenced by given array, if mapped.
*/
static void
-unmap_array_buffer(struct gl_context *ctx, struct gl_client_array *array)
+unmap_array_buffer(struct gl_context *ctx, struct gl_vertex_array_object *vao,
+ GLuint attrib)
{
- if (array->Enabled &&
- _mesa_is_bufferobj(array->BufferObj) &&
- _mesa_bufferobj_mapped(array->BufferObj, MAP_INTERNAL)) {
- ctx->Driver.UnmapBuffer(ctx, array->BufferObj, MAP_INTERNAL);
+ const struct gl_array_attributes *array = &vao->VertexAttrib[attrib];
+ if (array->Enabled) {
+ const struct gl_vertex_buffer_binding *binding =
+ &vao->VertexBinding[array->BufferBindingIndex];
+ struct gl_buffer_object *bo = binding->BufferObj;
+ if (_mesa_is_bufferobj(bo) && _mesa_bufferobj_mapped(bo, MAP_INTERNAL)) {
+ ctx->Driver.UnmapBuffer(ctx, bo, MAP_INTERNAL);
+ }
}
}
}
/* check element j of each enabled array */
- for (k = 0; k < ARRAY_SIZE(vao->_VertexAttrib); k++) {
- check_array_data(ctx, &vao->_VertexAttrib[k], k, j);
+ for (k = 0; k < VERT_ATTRIB_MAX; k++) {
+ check_array_data(ctx, vao, k, j);
}
}
MAP_INTERNAL);
}
- for (k = 0; k < ARRAY_SIZE(vao->_VertexAttrib); k++) {
- unmap_array_buffer(ctx, &vao->_VertexAttrib[k]);
+ for (k = 0; k < VERT_ATTRIB_MAX; k++) {
+ unmap_array_buffer(ctx, vao, k);
}
}
print_draw_arrays(struct gl_context *ctx,
GLenum mode, GLint start, GLsizei count)
{
- struct vbo_context *vbo = vbo_context(ctx);
- struct vbo_exec_context *exec = &vbo->exec;
- struct gl_vertex_array_object *vao = ctx->Array.VAO;
- int i;
+ const struct gl_vertex_array_object *vao = ctx->Array.VAO;
printf("vbo_exec_DrawArrays(mode 0x%x, start %d, count %d):\n",
mode, start, count);
- for (i = 0; i < 32; i++) {
- struct gl_buffer_object *bufObj = exec->array.inputs[i]->BufferObj;
- GLuint bufName = bufObj->Name;
- GLint stride = exec->array.inputs[i]->Stride;
- printf("attr %2d: size %d stride %d enabled %d "
+ 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->VertexBinding[array->BufferBindingIndex];
+ struct gl_buffer_object *bufObj = binding->BufferObj;
+
+ printf("attr %s: size %d stride %d enabled %d "
"ptr %p Bufobj %u\n",
- i,
- exec->array.inputs[i]->Size,
- stride,
- /*exec->array.inputs[i]->Enabled,*/
- vao->_VertexAttrib[VERT_ATTRIB_FF(i)].Enabled,
- exec->array.inputs[i]->Ptr,
- bufName);
-
- if (bufName) {
+ gl_vert_attrib_name((gl_vert_attrib)i),
+ array->Size, binding->Stride, array->Enabled,
+ array->Ptr, bufObj->Name);
+
+ if (_mesa_is_bufferobj(bufObj)) {
GLubyte *p = ctx->Driver.MapBufferRange(ctx, 0, bufObj->Size,
GL_MAP_READ_BIT, bufObj,
MAP_INTERNAL);
- int offset = (int) (GLintptr) exec->array.inputs[i]->Ptr;
+ int offset = (int) (GLintptr)
+ _mesa_vertex_attrib_address(array, binding);
float *f = (float *) (p + offset);
int *k = (int *) f;
int i;
- int n = (count * stride) / 4;
+ int n = (count * binding->Stride) / 4;
if (n > 32)
n = 32;
printf(" Data at offset %d:\n", offset);
{
struct vbo_context *vbo = vbo_context(ctx);
struct vbo_exec_context *exec = &vbo->exec;
+ const struct gl_array_attributes *array = ctx->Array.VAO->VertexAttrib;
struct gl_client_array *vertexAttrib = ctx->Array.VAO->_VertexAttrib;
const struct gl_client_array **inputs = &exec->array.inputs[0];
GLbitfield64 const_inputs = 0x0;
* are available as per-vertex attributes.
*/
for (i = 0; i < VERT_ATTRIB_FF_MAX; i++) {
- if (vertexAttrib[VERT_ATTRIB_FF(i)].Enabled)
+ if (array[VERT_ATTRIB_FF(i)].Enabled)
inputs[i] = &vertexAttrib[VERT_ATTRIB_FF(i)];
else {
inputs[i] = &vbo->currval[VBO_ATTRIB_POS+i];
* slots are considered "magic."
*/
if (ctx->API == API_OPENGL_COMPAT) {
- if (vertexAttrib[VERT_ATTRIB_GENERIC0].Enabled)
+ if (array[VERT_ATTRIB_GENERIC0].Enabled)
inputs[0] = &vertexAttrib[VERT_ATTRIB_GENERIC0];
- else if (vertexAttrib[VERT_ATTRIB_POS].Enabled)
+ else if (array[VERT_ATTRIB_POS].Enabled)
inputs[0] = &vertexAttrib[VERT_ATTRIB_POS];
else {
inputs[0] = &vbo->currval[VBO_ATTRIB_POS];
}
for (i = 1; i < VERT_ATTRIB_FF_MAX; i++) {
- if (vertexAttrib[VERT_ATTRIB_FF(i)].Enabled)
+ if (array[VERT_ATTRIB_FF(i)].Enabled)
inputs[i] = &vertexAttrib[VERT_ATTRIB_FF(i)];
else {
inputs[i] = &vbo->currval[VBO_ATTRIB_POS+i];
}
for (i = 1; i < VERT_ATTRIB_GENERIC_MAX; i++) {
- if (vertexAttrib[VERT_ATTRIB_GENERIC(i)].Enabled)
+ if (array[VERT_ATTRIB_GENERIC(i)].Enabled)
inputs[VERT_ATTRIB_GENERIC(i)] =
&vertexAttrib[VERT_ATTRIB_GENERIC(i)];
else {
* be enabled.
*/
for (i = 0; i < VERT_ATTRIB_FF_MAX; i++) {
- assert(!vertexAttrib[VERT_ATTRIB_FF(i)].Enabled);
+ assert(!array[VERT_ATTRIB_FF(i)].Enabled);
inputs[i] = &vbo->currval[VBO_ATTRIB_POS+i];
const_inputs |= VERT_BIT_FF(i);
}
for (i = 0; i < VERT_ATTRIB_GENERIC_MAX; i++) {
- if (vertexAttrib[VERT_ATTRIB_GENERIC(i)].Enabled)
+ if (array[VERT_ATTRIB_GENERIC(i)].Enabled)
inputs[VERT_ATTRIB_GENERIC(i)] =
&vertexAttrib[VERT_ATTRIB_GENERIC(i)];
else {
* Note that this might set the _NEW_VARYING_VP_INPUTS dirty flag so state
* validation must be done after this call.
*/
-bool
+void
vbo_bind_arrays(struct gl_context *ctx)
{
struct vbo_context *vbo = vbo_context(ctx);
exec->validating = GL_FALSE;
}
}
-
- if (!check_buffers_are_unmapped(ctx)) {
- _mesa_error(ctx, GL_INVALID_OPERATION,
- "draw call (vertex buffers are mapped)");
- return false;
- } else {
- return true;
- }
}
/**
struct vbo_context *vbo = vbo_context(ctx);
struct _mesa_prim prim[2];
- if (!vbo_bind_arrays(ctx))
- return;
+ vbo_bind_arrays(ctx);
/* init most fields to zero */
memset(prim, 0, sizeof(prim));
struct _mesa_index_buffer ib;
struct _mesa_prim prim[1];
- if (!vbo_bind_arrays(ctx))
- return;
+ vbo_bind_arrays(ctx);
ib.count = count;
ib.type = type;
prim[0].basevertex = basevertex;
prim[0].num_instances = numInstances;
prim[0].base_instance = baseInstance;
+ prim[0].draw_id = 0;
/* Need to give special consideration to rendering a range of
* indices starting somewhere above zero. Typically the
index_bounds_valid = GL_FALSE;
#if 0
- check_draw_elements_data(ctx, count, type, indices);
+ check_draw_elements_data(ctx, count, type, indices, basevertex);
#else
(void) check_draw_elements_data;
#endif
return;
}
- if (!vbo_bind_arrays(ctx)) {
- free(prim);
- return;
- }
+ vbo_bind_arrays(ctx);
min_index_ptr = (uintptr_t)indices[0];
max_index_ptr = 0;
GLuint stream, GLuint numInstances)
{
struct vbo_context *vbo = vbo_context(ctx);
- struct vbo_exec_context *exec = &vbo->exec;
struct _mesa_prim prim[2];
if (!_mesa_validate_DrawTransformFeedback(ctx, mode, obj, stream,
if (ctx->Driver.GetTransformFeedbackVertexCount &&
(ctx->Const.AlwaysUseGetTransformFeedbackVertexCount ||
- !vbo_all_varyings_in_vbos(exec->array.inputs))) {
+ !_mesa_all_varyings_in_vbos(ctx->Array.VAO))) {
GLsizei n = ctx->Driver.GetTransformFeedbackVertexCount(ctx, obj, stream);
vbo_draw_arrays(ctx, mode, 0, n, numInstances, 0);
return;
}
- if (!vbo_bind_arrays(ctx))
- return;
+ vbo_bind_arrays(ctx);
/* init most fields to zero */
memset(prim, 0, sizeof(prim));
{
struct vbo_context *vbo = vbo_context(ctx);
- if (!vbo_bind_arrays(ctx))
- return;
+ vbo_bind_arrays(ctx);
vbo->draw_indirect_prims(ctx, mode,
ctx->DrawIndirectBuffer, (GLsizeiptr)indirect,
if (primcount == 0)
return;
- if (!vbo_bind_arrays(ctx))
- return;
+ vbo_bind_arrays(ctx);
vbo->draw_indirect_prims(ctx, mode,
ctx->DrawIndirectBuffer, offset,
struct vbo_context *vbo = vbo_context(ctx);
struct _mesa_index_buffer ib;
- if (!vbo_bind_arrays(ctx))
- return;
+ vbo_bind_arrays(ctx);
ib.count = 0; /* unknown */
ib.type = type;
if (primcount == 0)
return;
- if (!vbo_bind_arrays(ctx))
- return;
+ vbo_bind_arrays(ctx);
/* NOTE: IndexBufferObj is guaranteed to be a VBO. */
if (maxdrawcount == 0)
return;
- if (!vbo_bind_arrays(ctx))
- return;
+ vbo_bind_arrays(ctx);
vbo->draw_indirect_prims(ctx, mode,
ctx->DrawIndirectBuffer, offset,
if (maxdrawcount == 0)
return;
- if (!vbo_bind_arrays(ctx))
- return;
+ vbo_bind_arrays(ctx);
/* NOTE: IndexBufferObj is guaranteed to be a VBO. */
if (MESA_VERBOSE & VERBOSE_DRAW)
_mesa_debug(ctx, "glMultiDrawArraysIndirectCountARB"
"(%s, %lx, %lx, %i, %i)\n",
- _mesa_enum_to_string(mode), indirect,
- drawcount, maxdrawcount, stride);
+ _mesa_enum_to_string(mode),
+ (unsigned long)indirect, (unsigned long)drawcount,
+ maxdrawcount, stride);
/* If <stride> is zero, the array elements are treated as tightly packed. */
if (stride == 0)
if (MESA_VERBOSE & VERBOSE_DRAW)
_mesa_debug(ctx, "glMultiDrawElementsIndirectCountARB"
"(%s, %s, %lx, %lx, %i, %i)\n",
- _mesa_enum_to_string(mode),
- _mesa_enum_to_string(type), indirect,
- drawcount, maxdrawcount, stride);
+ _mesa_enum_to_string(mode), _mesa_enum_to_string(type),
+ (unsigned long)indirect, (unsigned long)drawcount,
+ maxdrawcount, stride);
/* If <stride> is zero, the array elements are treated as tightly packed. */
if (stride == 0)