示例#1
0
/* TODO: populate these as the vertex is defined:
 */
static void
vbo_exec_bind_arrays(struct gl_context *ctx)
{
   struct vbo_context *vbo = vbo_context(ctx);
   struct gl_vertex_array_object *vao = vbo->VAO;
   struct vbo_exec_context *exec = &vbo->exec;

   GLintptr buffer_offset;
   if (_mesa_is_bufferobj(exec->vtx.bufferobj)) {
      assert(exec->vtx.bufferobj->Mappings[MAP_INTERNAL].Pointer);
      buffer_offset = exec->vtx.bufferobj->Mappings[MAP_INTERNAL].Offset;
   } else {
      /* Ptr into ordinary app memory */
      buffer_offset = (GLbyte *)exec->vtx.buffer_map - (GLbyte *)NULL;
   }

   const gl_vertex_processing_mode mode = ctx->VertexProgram._VPMode;

   /* Compute the bitmasks of vao_enabled arrays */
   GLbitfield vao_enabled = _vbo_get_vao_enabled_from_vbo(mode, exec->vtx.enabled);

   /* At first disable arrays no longer needed */
   _mesa_disable_vertex_array_attribs(ctx, vao, VERT_BIT_ALL & ~vao_enabled);
   assert((~vao_enabled & vao->Enabled) == 0);

   /* Bind the buffer object */
   const GLuint stride = exec->vtx.vertex_size*sizeof(GLfloat);
   _mesa_bind_vertex_buffer(ctx, vao, 0, exec->vtx.bufferobj, buffer_offset,
                            stride);

   /* Retrieve the mapping from VBO_ATTRIB to VERT_ATTRIB space
    * Note that the position/generic0 aliasing is done in the VAO.
    */
   const GLubyte *const vao_to_vbo_map = _vbo_attribute_alias_map[mode];
   /* Now set the enabled arrays */
   GLbitfield mask = vao_enabled;
   while (mask) {
      const int vao_attr = u_bit_scan(&mask);
      const GLubyte vbo_attr = vao_to_vbo_map[vao_attr];

      const GLubyte size = exec->vtx.attrsz[vbo_attr];
      const GLenum16 type = exec->vtx.attrtype[vbo_attr];
      const GLuint offset = (GLuint)((GLbyte *)exec->vtx.attrptr[vbo_attr] -
                                     (GLbyte *)exec->vtx.vertex);
      assert(offset <= ctx->Const.MaxVertexAttribRelativeOffset);

      /* Set and enable */
      _vbo_set_attrib_format(ctx, vao, vao_attr, buffer_offset,
                             size, type, offset);

      /* The vao is initially created with all bindings set to 0. */
      assert(vao->VertexAttrib[vao_attr].BufferBindingIndex == 0);
   }
   _mesa_enable_vertex_array_attribs(ctx, vao, vao_enabled);
   assert(vao_enabled == vao->Enabled);
   assert(!_mesa_is_bufferobj(exec->vtx.bufferobj) ||
          (vao_enabled & ~vao->VertexAttribBufferMask) == 0);

   _mesa_set_draw_vao(ctx, vao, _vbo_get_vao_filter(mode));
}
示例#2
0
static bool
brw_fast_clear_init(struct brw_context *brw)
{
   struct brw_fast_clear_state *clear;
   struct gl_context *ctx = &brw->ctx;

   if (brw->fast_clear_state) {
      clear = brw->fast_clear_state;
      _mesa_BindVertexArray(clear->vao);
      return true;
   }

   brw->fast_clear_state = clear = malloc(sizeof *clear);
   if (clear == NULL)
      return false;

   memset(clear, 0, sizeof *clear);
   _mesa_GenVertexArrays(1, &clear->vao);
   _mesa_BindVertexArray(clear->vao);

   clear->buf_obj = ctx->Driver.NewBufferObject(ctx, 0xDEADBEEF);
   if (clear->buf_obj == NULL)
      return false;

   clear->array_obj = _mesa_lookup_vao(ctx, clear->vao);
   assert(clear->array_obj != NULL);

   _mesa_update_array_format(ctx, clear->array_obj, VERT_ATTRIB_GENERIC(0),
                             2, GL_FLOAT, GL_RGBA, GL_FALSE, GL_FALSE, GL_FALSE,
                             0, true);
   _mesa_bind_vertex_buffer(ctx, clear->array_obj, VERT_ATTRIB_GENERIC(0),
                            clear->buf_obj, 0, sizeof(float) * 2);
   _mesa_enable_vertex_array_attrib(ctx, clear->array_obj,
                                    VERT_ATTRIB_GENERIC(0));

   return true;
}