Tizen 2.0 Release
[profile/ivi/osmesa.git] / src / gallium / auxiliary / util / u_vbuf_mgr.h
1 /**************************************************************************
2  *
3  * Copyright 2011 Marek Olšák <maraeo@gmail.com>
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sub license, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice (including the
15  * next paragraph) shall be included in all copies or substantial portions
16  * of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21  * IN NO EVENT SHALL AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR
22  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  *
26  **************************************************************************/
27
28 #ifndef U_VBUF_MGR_H
29 #define U_VBUF_MGR_H
30
31 /* This module builds upon u_upload_mgr and translate_cache and takes care of
32  * user buffer uploads and vertex format fallbacks. It's designed
33  * for the drivers which don't always use the Draw module. (e.g. for HWTCL)
34  */
35
36 #include "pipe/p_context.h"
37 #include "pipe/p_state.h"
38 #include "util/u_transfer.h"
39
40 /* The manager.
41  * This structure should also be used to access vertex buffers
42  * from a driver. */
43 struct u_vbuf_mgr {
44    /* This is what was set in set_vertex_buffers.
45     * May contain user buffers. */
46    struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
47    unsigned nr_vertex_buffers;
48
49    /* Contains only real vertex buffers.
50     * Hardware drivers should use real_vertex_buffers[i]
51     * instead of vertex_buffers[i].buffer. */
52    struct pipe_vertex_buffer real_vertex_buffer[PIPE_MAX_ATTRIBS];
53    int nr_real_vertex_buffers;
54
55    /* Precomputed max_index for hardware vertex buffers. */
56    unsigned max_index;
57
58    /* This uploader can optionally be used by the driver.
59     *
60     * Allowed functions:
61     * - u_upload_alloc
62     * - u_upload_data
63     * - u_upload_buffer
64     * - u_upload_flush */
65    struct u_upload_mgr *uploader;
66 };
67
68 struct u_vbuf_resource {
69    struct u_resource b;
70    uint8_t *user_ptr;
71 };
72
73 /* Opaque type containing information about vertex elements for the manager. */
74 struct u_vbuf_elements;
75
76 enum u_fetch_alignment {
77    U_VERTEX_FETCH_BYTE_ALIGNED,
78    U_VERTEX_FETCH_DWORD_ALIGNED
79 };
80
81 enum u_vbuf_return_flags {
82    U_VBUF_BUFFERS_UPDATED = 1
83 };
84
85
86 struct u_vbuf_mgr *
87 u_vbuf_create(struct pipe_context *pipe,
88               unsigned upload_buffer_size,
89               unsigned upload_buffer_alignment,
90               unsigned upload_buffer_bind,
91               enum u_fetch_alignment fetch_alignment);
92
93 void u_vbuf_destroy(struct u_vbuf_mgr *mgr);
94
95 struct u_vbuf_elements *
96 u_vbuf_create_vertex_elements(struct u_vbuf_mgr *mgr,
97                               unsigned count,
98                               const struct pipe_vertex_element *attrs,
99                               struct pipe_vertex_element *native_attrs);
100
101 void u_vbuf_bind_vertex_elements(struct u_vbuf_mgr *mgr,
102                                  void *cso,
103                                  struct u_vbuf_elements *ve);
104
105 void u_vbuf_destroy_vertex_elements(struct u_vbuf_mgr *mgr,
106                                     struct u_vbuf_elements *ve);
107
108 void u_vbuf_set_vertex_buffers(struct u_vbuf_mgr *mgr,
109                                unsigned count,
110                                const struct pipe_vertex_buffer *bufs);
111
112 enum u_vbuf_return_flags u_vbuf_draw_begin(struct u_vbuf_mgr *mgr,
113                                            const struct pipe_draw_info *info);
114
115 void u_vbuf_draw_end(struct u_vbuf_mgr *mgr);
116
117
118 static INLINE struct u_vbuf_resource *u_vbuf_resource(struct pipe_resource *r)
119 {
120    return (struct u_vbuf_resource*)r;
121 }
122
123 #endif