"Initial commit to Gerrit"
[profile/ivi/cogl.git] / cogl / cogl-attribute-buffer.c
1 /*
2  * Cogl
3  *
4  * An object oriented GL/GLES Abstraction/Utility Layer
5  *
6  * Copyright (C) 2010 Intel Corporation.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library. If not, see
20  * <http://www.gnu.org/licenses/>.
21  *
22  *
23  *
24  * Authors:
25  *   Robert Bragg <robert@linux.intel.com>
26  */
27
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31
32 #include "cogl-object-private.h"
33 #include "cogl-attribute-buffer.h"
34 #include "cogl-attribute-buffer-private.h"
35 #include "cogl-context-private.h"
36
37 static void _cogl_attribute_buffer_free (CoglAttributeBuffer *array);
38
39 COGL_BUFFER_DEFINE (AttributeBuffer, attribute_buffer);
40
41 CoglAttributeBuffer *
42 cogl_attribute_buffer_new (CoglContext *context,
43                            gsize bytes,
44                            const void *data)
45 {
46   CoglAttributeBuffer *array = g_slice_new (CoglAttributeBuffer);
47   gboolean use_malloc;
48
49   if (!(context->private_feature_flags & COGL_PRIVATE_FEATURE_VBOS))
50     use_malloc = TRUE;
51   else
52     use_malloc = FALSE;
53
54   /* parent's constructor */
55   _cogl_buffer_initialize (COGL_BUFFER (array),
56                            context,
57                            bytes,
58                            use_malloc,
59                            COGL_BUFFER_BIND_TARGET_ATTRIBUTE_BUFFER,
60                            COGL_BUFFER_USAGE_HINT_ATTRIBUTE_BUFFER,
61                            COGL_BUFFER_UPDATE_HINT_STATIC);
62
63   _cogl_attribute_buffer_object_new (array);
64
65   if (data)
66     cogl_buffer_set_data (COGL_BUFFER (array),
67                           0,
68                           data,
69                           bytes);
70   return array;
71 }
72
73 static void
74 _cogl_attribute_buffer_free (CoglAttributeBuffer *array)
75 {
76   /* parent's destructor */
77   _cogl_buffer_fini (COGL_BUFFER (array));
78
79   g_slice_free (CoglAttributeBuffer, array);
80 }
81