Esempio n. 1
0
CoglAttributeBuffer *
cogl_attribute_buffer_new (CoglContext *context,
                           size_t bytes,
                           const void *data)
{
  CoglAttributeBuffer *array = g_slice_new (CoglAttributeBuffer);
  CoglBool use_malloc;

  if (!(context->private_feature_flags & COGL_PRIVATE_FEATURE_VBOS))
    use_malloc = TRUE;
  else
    use_malloc = FALSE;

  /* parent's constructor */
  _cogl_buffer_initialize (COGL_BUFFER (array),
                           context,
                           bytes,
                           use_malloc,
                           COGL_BUFFER_BIND_TARGET_ATTRIBUTE_BUFFER,
                           COGL_BUFFER_USAGE_HINT_ATTRIBUTE_BUFFER,
                           COGL_BUFFER_UPDATE_HINT_STATIC);

  _cogl_attribute_buffer_object_new (array);

  if (data)
    cogl_buffer_set_data (COGL_BUFFER (array),
                          0,
                          data,
                          bytes);
  return array;
}
Esempio n. 2
0
CoglVertexArray *
cogl_vertex_array_new (gsize bytes, const void *data)
{
    CoglVertexArray *array = g_slice_new (CoglVertexArray);
    gboolean use_malloc;

    if (!cogl_features_available (COGL_FEATURE_VBOS))
        use_malloc = TRUE;
    else
        use_malloc = FALSE;

    /* parent's constructor */
    _cogl_buffer_initialize (COGL_BUFFER (array),
                             bytes,
                             use_malloc,
                             COGL_BUFFER_BIND_TARGET_VERTEX_ARRAY,
                             COGL_BUFFER_USAGE_HINT_VERTEX_ARRAY,
                             COGL_BUFFER_UPDATE_HINT_STATIC);

    _cogl_vertex_array_object_new (array);

    if (data)
        cogl_buffer_set_data (COGL_BUFFER (array),
                              0,
                              data,
                              bytes);
    return array;
}
Esempio n. 3
0
/* XXX: Unlike the wiki design this just takes a size. A single
 * indices buffer should be able to contain multiple ranges of indices
 * which the wiki design doesn't currently consider. */
CoglIndexBuffer *
cogl_index_buffer_new (CoglContext *context, size_t bytes)
{
  CoglIndexBuffer *indices = g_slice_new (CoglIndexBuffer);

  /* parent's constructor */
  _cogl_buffer_initialize (COGL_BUFFER (indices),
                           context,
                           bytes,
                           COGL_BUFFER_BIND_TARGET_INDEX_BUFFER,
                           COGL_BUFFER_USAGE_HINT_INDEX_BUFFER,
                           COGL_BUFFER_UPDATE_HINT_STATIC);

  return _cogl_index_buffer_object_new (indices);
}
Esempio n. 4
0
CoglHandle
cogl_pixel_buffer_new_EXP (unsigned int size)
{
  CoglPixelBuffer *pixel_buffer = g_slice_new0 (CoglPixelBuffer);
  CoglBuffer *buffer = COGL_BUFFER (pixel_buffer);

  _COGL_GET_CONTEXT (ctx, COGL_INVALID_HANDLE);

  /* parent's constructor */
  _cogl_buffer_initialize (buffer,
                           size,
                           COGL_BUFFER_USAGE_HINT_TEXTURE,
                           COGL_BUFFER_UPDATE_HINT_STATIC);

/* malloc version only for GLES */
#if !defined (COGL_HAS_GLES)
  if (cogl_features_available (COGL_FEATURE_PBOS))
    {
      /* PBOS */
      buffer->vtable = &cogl_pixel_buffer_vtable;

      GE( glGenBuffers (1, &buffer->gl_handle) );
      COGL_BUFFER_SET_FLAG (buffer, BUFFER_OBJECT);
    }
  else
#endif
    {
      /* malloc fallback subclass */
      buffer->vtable = &cogl_malloc_pixel_buffer_vtable;

      /* create the buffer here as there's no point for a lazy allocation in
       * the malloc case */
      buffer->data = g_malloc (size);
    }

  pixel_buffer->flags = COGL_PIXEL_BUFFER_FLAG_NONE;

  /* return COGL_INVALID_HANDLE; */
  return _cogl_pixel_buffer_handle_new (pixel_buffer);
}