1 /*
2  * mesa 3-D graphics library
3  *
4  * Copyright (C) 1999-2006  Brian Paul   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 "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22  * OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
25 /**
26  * \brief Public interface to the VBO module
27  * \author Keith Whitwell
28  */
29 
30 
31 #ifndef _VBO_H
32 #define _VBO_H
33 
34 #include <stdbool.h>
35 #include "main/glheader.h"
36 #include "main/dd.h"
37 #include "main/draw.h"
38 #include "main/macros.h"
39 #include "vbo_attrib.h"
40 #include "gallium/include/pipe/p_state.h"
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 struct gl_context;
47 struct pipe_draw_info;
48 struct pipe_draw_start_count_bias;
49 
50 /**
51  * Max number of primitives (number of glBegin/End pairs) per VBO.
52  */
53 #define VBO_MAX_PRIM 64
54 
55 
56 /**
57  * Current vertex processing mode: fixed function vs. shader.
58  * In reality, fixed function is probably implemented by a shader but that's
59  * not what we care about here.
60  */
61 typedef enum
62 {
63    VP_MODE_FF,     /**< legacy / fixed function */
64    VP_MODE_SHADER, /**< ARB vertex program or GLSL vertex shader */
65    VP_MODE_MAX     /**< for sizing arrays */
66 } gl_vertex_processing_mode;
67 
68 
69 struct vbo_exec_eval1_map {
70    struct gl_1d_map *map;
71    GLuint sz;
72 };
73 
74 struct vbo_exec_eval2_map {
75    struct gl_2d_map *map;
76    GLuint sz;
77 };
78 
79 struct vbo_exec_copied_vtx {
80    fi_type buffer[VBO_ATTRIB_MAX * 4 * VBO_MAX_COPIED_VERTS];
81    GLuint nr;
82 };
83 
84 struct vbo_markers
85 {
86    /**
87     * If false and the primitive is a line loop, the first vertex is
88     * the beginning of the line loop and it won't be drawn.
89     * Instead, it will be moved to the end.
90     *
91     * Drivers shouldn't reset the line stipple pattern walker if begin is
92     * false and mode is a line strip.
93     */
94    bool begin;
95 
96    /**
97     * If true and the primitive is a line loop, it will be closed.
98     */
99    bool end;
100 };
101 
102 struct vbo_exec_context
103 {
104    GLvertexformat vtxfmt;
105    GLvertexformat vtxfmt_noop;
106 
107    struct {
108       /* Multi draw where the mode can vary between draws. */
109       struct pipe_draw_info info;
110       struct pipe_draw_start_count_bias draw[VBO_MAX_PRIM];
111       GLubyte mode[VBO_MAX_PRIM];            /**< primitive modes per draw */
112       struct vbo_markers markers[VBO_MAX_PRIM];
113       unsigned prim_count;
114 
115       struct gl_buffer_object *bufferobj;
116 
117       GLuint vertex_size;       /* in dwords */
118       GLuint vertex_size_no_pos;
119 
120       fi_type *buffer_map;
121       fi_type *buffer_ptr;              /* cursor, points into buffer */
122       GLuint   buffer_used;             /* in bytes */
123       unsigned buffer_offset;           /* only for persistent mappings */
124       fi_type vertex[VBO_ATTRIB_MAX*4]; /* current vertex */
125 
126       GLuint vert_count;   /**< Number of vertices currently in buffer */
127       GLuint max_vert;     /**< Max number of vertices allowed in buffer */
128       struct vbo_exec_copied_vtx copied;
129 
130       GLbitfield64 enabled;             /**< mask of enabled vbo arrays. */
131 
132       /* Keep these packed in a structure for faster access. */
133       struct {
134          GLenum16 type;       /**< GL_FLOAT, GL_DOUBLE, GL_INT, etc */
135          GLubyte active_size; /**< number of components, but can shrink */
136          GLubyte size;        /**< number of components (1..4) */
137       } attr[VBO_ATTRIB_MAX];
138 
139       /** pointers into the current 'vertex' array, declared above */
140       fi_type *attrptr[VBO_ATTRIB_MAX];
141    } vtx;
142 
143    struct {
144       GLboolean recalculate_maps;
145       struct vbo_exec_eval1_map map1[VERT_ATTRIB_MAX];
146       struct vbo_exec_eval2_map map2[VERT_ATTRIB_MAX];
147    } eval;
148 
149 #ifndef NDEBUG
150    GLint flush_call_depth;
151 #endif
152 };
153 
154 
155 struct vbo_save_context {
156    GLvertexformat vtxfmt;
157 
158    GLbitfield64 enabled; /**< mask of enabled vbo arrays. */
159    GLubyte attrsz[VBO_ATTRIB_MAX];  /**< 1, 2, 3 or 4 */
160    GLenum16 attrtype[VBO_ATTRIB_MAX];  /**< GL_FLOAT, GL_INT, etc */
161    GLubyte active_sz[VBO_ATTRIB_MAX];  /**< 1, 2, 3 or 4 */
162    GLuint vertex_size;  /**< size in GLfloats */
163    struct gl_vertex_array_object *VAO[VP_MODE_MAX];
164 
165    struct vbo_save_vertex_store *vertex_store;
166    struct vbo_save_primitive_store *prim_store;
167    struct gl_buffer_object *current_bo;
168    unsigned current_bo_bytes_used;
169 
170    fi_type vertex[VBO_ATTRIB_MAX*4];	   /* current values */
171    fi_type *attrptr[VBO_ATTRIB_MAX];
172 
173    struct {
174       fi_type *buffer;
175       GLuint nr;
176    } copied;
177 
178    fi_type *current[VBO_ATTRIB_MAX]; /* points into ctx->ListState */
179    GLubyte *currentsz[VBO_ATTRIB_MAX];
180 
181    GLboolean dangling_attr_ref;
182    GLboolean out_of_memory;  /**< True if last VBO allocation failed */
183    bool no_current_update;
184 };
185 
186 GLboolean
187 _vbo_CreateContext(struct gl_context *ctx, bool use_buffer_objects);
188 
189 void
190 _vbo_DestroyContext(struct gl_context *ctx);
191 
192 void
193 vbo_exec_update_eval_maps(struct gl_context *ctx);
194 
195 void
196 _vbo_install_exec_vtxfmt(struct gl_context *ctx);
197 
198 void
199 vbo_initialize_exec_dispatch(const struct gl_context *ctx,
200                              struct _glapi_table *exec);
201 
202 void
203 vbo_initialize_save_dispatch(const struct gl_context *ctx,
204                              struct _glapi_table *exec);
205 
206 void
207 vbo_exec_FlushVertices(struct gl_context *ctx, GLuint flags);
208 
209 void
210 vbo_save_SaveFlushVertices(struct gl_context *ctx);
211 
212 void
213 vbo_save_NotifyBegin(struct gl_context *ctx, GLenum mode,
214                      bool no_current_update);
215 
216 void
217 vbo_save_NewList(struct gl_context *ctx, GLuint list, GLenum mode);
218 
219 void
220 vbo_save_EndList(struct gl_context *ctx);
221 
222 void
223 vbo_delete_minmax_cache(struct gl_buffer_object *bufferObj);
224 
225 void
226 vbo_get_minmax_index_mapped(unsigned count, unsigned index_size,
227                             unsigned restartIndex, bool restart,
228                             const void *indices,
229                             unsigned *min_index, unsigned *max_index);
230 
231 void
232 vbo_get_minmax_indices(struct gl_context *ctx, const struct _mesa_prim *prim,
233                        const struct _mesa_index_buffer *ib,
234                        GLuint *min_index, GLuint *max_index, GLuint nr_prims,
235                        bool primitive_restart,
236                        unsigned restart_index);
237 
238 bool
239 vbo_get_minmax_indices_gallium(struct gl_context *ctx,
240                                struct pipe_draw_info *info,
241                                const struct pipe_draw_start_count_bias *draws,
242                                unsigned num_draws);
243 
244 const struct gl_array_attributes*
245 _vbo_current_attrib(const struct gl_context *ctx, gl_vert_attrib attr);
246 
247 
248 const struct gl_vertex_buffer_binding*
249 _vbo_current_binding(const struct gl_context *ctx);
250 
251 
252 void GLAPIENTRY
253 _es_Color4f(GLfloat r, GLfloat g, GLfloat b, GLfloat a);
254 
255 void GLAPIENTRY
256 _es_Normal3f(GLfloat x, GLfloat y, GLfloat z);
257 
258 void GLAPIENTRY
259 _es_MultiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q);
260 
261 void GLAPIENTRY
262 _es_Materialfv(GLenum face, GLenum pname, const GLfloat *params);
263 
264 void GLAPIENTRY
265 _es_Materialf(GLenum face, GLenum pname, GLfloat param);
266 
267 void GLAPIENTRY
268 _es_VertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
269 
270 void GLAPIENTRY
271 _es_VertexAttrib1f(GLuint indx, GLfloat x);
272 
273 void GLAPIENTRY
274 _es_VertexAttrib1fv(GLuint indx, const GLfloat* values);
275 
276 void GLAPIENTRY
277 _es_VertexAttrib2f(GLuint indx, GLfloat x, GLfloat y);
278 
279 void GLAPIENTRY
280 _es_VertexAttrib2fv(GLuint indx, const GLfloat* values);
281 
282 void GLAPIENTRY
283 _es_VertexAttrib3f(GLuint indx, GLfloat x, GLfloat y, GLfloat z);
284 
285 void GLAPIENTRY
286 _es_VertexAttrib3fv(GLuint indx, const GLfloat* values);
287 
288 void GLAPIENTRY
289 _es_VertexAttrib4fv(GLuint indx, const GLfloat* values);
290 
291 #ifdef __cplusplus
292 } // extern "C"
293 #endif
294 
295 #endif
296