• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 struct gl_context;
46 struct vbo_module;
47 
48 /**
49  * Max number of primitives (number of glBegin/End pairs) per VBO.
50  */
51 #define VBO_MAX_PRIM 64
52 
53 
54 /**
55  * Current vertex processing mode: fixed function vs. shader.
56  * In reality, fixed function is probably implemented by a shader but that's
57  * not what we care about here.
58  */
59 typedef enum
60 {
61    VP_MODE_FF,     /**< legacy / fixed function */
62    VP_MODE_SHADER, /**< ARB vertex program or GLSL vertex shader */
63    VP_MODE_MAX     /**< for sizing arrays */
64 } gl_vertex_processing_mode;
65 
66 
67 struct vbo_exec_eval1_map {
68    struct gl_1d_map *map;
69    GLuint sz;
70 };
71 
72 struct vbo_exec_eval2_map {
73    struct gl_2d_map *map;
74    GLuint sz;
75 };
76 
77 struct vbo_exec_copied_vtx {
78    fi_type buffer[VBO_ATTRIB_MAX * 4 * VBO_MAX_COPIED_VERTS];
79    GLuint nr;
80 };
81 
82 struct vbo_exec_context
83 {
84    struct gl_context *ctx;
85    GLvertexformat vtxfmt;
86    GLvertexformat vtxfmt_noop;
87 
88    struct {
89       struct gl_buffer_object *bufferobj;
90 
91       GLuint vertex_size;       /* in dwords */
92       GLuint vertex_size_no_pos;
93 
94       struct _mesa_prim prim[VBO_MAX_PRIM];
95       GLuint prim_count;
96 
97       fi_type *buffer_map;
98       fi_type *buffer_ptr;              /* cursor, points into buffer */
99       GLuint   buffer_used;             /* in bytes */
100       unsigned buffer_offset;           /* only for persistent mappings */
101       fi_type vertex[VBO_ATTRIB_MAX*4]; /* current vertex */
102 
103       GLuint vert_count;   /**< Number of vertices currently in buffer */
104       GLuint max_vert;     /**< Max number of vertices allowed in buffer */
105       struct vbo_exec_copied_vtx copied;
106 
107       GLbitfield64 enabled;             /**< mask of enabled vbo arrays. */
108 
109       /* Keep these packed in a structure for faster access. */
110       struct {
111          GLenum16 type;       /**< GL_FLOAT, GL_DOUBLE, GL_INT, etc */
112          GLubyte active_size; /**< number of components, but can shrink */
113          GLubyte size;        /**< number of components (1..4) */
114       } attr[VBO_ATTRIB_MAX];
115 
116       /** pointers into the current 'vertex' array, declared above */
117       fi_type *attrptr[VBO_ATTRIB_MAX];
118    } vtx;
119 
120    struct {
121       GLboolean recalculate_maps;
122       struct vbo_exec_eval1_map map1[VERT_ATTRIB_MAX];
123       struct vbo_exec_eval2_map map2[VERT_ATTRIB_MAX];
124    } eval;
125 
126 #ifndef NDEBUG
127    GLint flush_call_depth;
128 #endif
129 };
130 
131 struct vbo_save_copied_vtx {
132    fi_type buffer[VBO_ATTRIB_MAX * 4 * VBO_MAX_COPIED_VERTS];
133    GLuint nr;
134 };
135 
136 struct vbo_save_context {
137    struct gl_context *ctx;
138    GLvertexformat vtxfmt;
139    GLvertexformat vtxfmt_noop;  /**< Used if out_of_memory is true */
140 
141    GLbitfield64 enabled; /**< mask of enabled vbo arrays. */
142    GLubyte attrsz[VBO_ATTRIB_MAX];  /**< 1, 2, 3 or 4 */
143    GLenum16 attrtype[VBO_ATTRIB_MAX];  /**< GL_FLOAT, GL_INT, etc */
144    GLubyte active_sz[VBO_ATTRIB_MAX];  /**< 1, 2, 3 or 4 */
145    GLuint vertex_size;  /**< size in GLfloats */
146    struct gl_vertex_array_object *VAO[VP_MODE_MAX];
147 
148    GLboolean out_of_memory;  /**< True if last VBO allocation failed */
149 
150    GLbitfield replay_flags;
151 
152    struct _mesa_prim *prims;
153    GLuint prim_count, prim_max;
154 
155    bool no_current_update;
156 
157    struct vbo_save_vertex_store *vertex_store;
158    struct vbo_save_primitive_store *prim_store;
159 
160    fi_type *buffer_map;            /**< Mapping of vertex_store's buffer */
161    fi_type *buffer_ptr;		   /**< cursor, points into buffer_map */
162    fi_type vertex[VBO_ATTRIB_MAX*4];	   /* current values */
163    fi_type *attrptr[VBO_ATTRIB_MAX];
164    GLuint vert_count;
165    GLuint max_vert;
166    GLboolean dangling_attr_ref;
167 
168    GLuint opcode_vertex_list;
169 
170    struct vbo_save_copied_vtx copied;
171 
172    fi_type *current[VBO_ATTRIB_MAX]; /* points into ctx->ListState */
173    GLubyte *currentsz[VBO_ATTRIB_MAX];
174 };
175 
176 GLboolean
177 _vbo_CreateContext(struct gl_context *ctx, bool use_buffer_objects);
178 
179 void
180 _vbo_DestroyContext(struct gl_context *ctx);
181 
182 void
183 vbo_exec_update_eval_maps(struct gl_context *ctx);
184 
185 void
186 _vbo_install_exec_vtxfmt(struct gl_context *ctx);
187 
188 void
189 vbo_initialize_exec_dispatch(const struct gl_context *ctx,
190                              struct _glapi_table *exec);
191 
192 void
193 vbo_initialize_save_dispatch(const struct gl_context *ctx,
194                              struct _glapi_table *exec);
195 
196 void
197 vbo_exec_FlushVertices(struct gl_context *ctx, GLuint flags);
198 
199 void
200 vbo_save_SaveFlushVertices(struct gl_context *ctx);
201 
202 void
203 vbo_save_NotifyBegin(struct gl_context *ctx, GLenum mode,
204                      bool no_current_update);
205 
206 void
207 vbo_save_NewList(struct gl_context *ctx, GLuint list, GLenum mode);
208 
209 void
210 vbo_save_EndList(struct gl_context *ctx);
211 
212 void
213 vbo_save_BeginCallList(struct gl_context *ctx, struct gl_display_list *list);
214 
215 void
216 vbo_save_EndCallList(struct gl_context *ctx);
217 
218 
219 void
220 vbo_delete_minmax_cache(struct gl_buffer_object *bufferObj);
221 
222 void
223 vbo_get_minmax_index_mapped(unsigned count, unsigned index_size,
224                             unsigned restartIndex, bool restart,
225                             const void *indices,
226                             unsigned *min_index, unsigned *max_index);
227 
228 void
229 vbo_get_minmax_indices(struct gl_context *ctx, const struct _mesa_prim *prim,
230                        const struct _mesa_index_buffer *ib,
231                        GLuint *min_index, GLuint *max_index, GLuint nr_prims);
232 
233 void
234 vbo_sw_primitive_restart(struct gl_context *ctx,
235                          const struct _mesa_prim *prim,
236                          GLuint nr_prims,
237                          const struct _mesa_index_buffer *ib,
238                          GLuint num_instances, GLuint base_instance,
239                          struct gl_buffer_object *indirect,
240                          GLsizeiptr indirect_offset);
241 
242 
243 const struct gl_array_attributes*
244 _vbo_current_attrib(const struct gl_context *ctx, gl_vert_attrib attr);
245 
246 
247 const struct gl_vertex_buffer_binding*
248 _vbo_current_binding(const struct gl_context *ctx);
249 
250 
251 void GLAPIENTRY
252 _es_Color4f(GLfloat r, GLfloat g, GLfloat b, GLfloat a);
253 
254 void GLAPIENTRY
255 _es_Normal3f(GLfloat x, GLfloat y, GLfloat z);
256 
257 void GLAPIENTRY
258 _es_MultiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q);
259 
260 void GLAPIENTRY
261 _es_Materialfv(GLenum face, GLenum pname, const GLfloat *params);
262 
263 void GLAPIENTRY
264 _es_Materialf(GLenum face, GLenum pname, GLfloat param);
265 
266 void GLAPIENTRY
267 _es_VertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
268 
269 void GLAPIENTRY
270 _es_VertexAttrib1f(GLuint indx, GLfloat x);
271 
272 void GLAPIENTRY
273 _es_VertexAttrib1fv(GLuint indx, const GLfloat* values);
274 
275 void GLAPIENTRY
276 _es_VertexAttrib2f(GLuint indx, GLfloat x, GLfloat y);
277 
278 void GLAPIENTRY
279 _es_VertexAttrib2fv(GLuint indx, const GLfloat* values);
280 
281 void GLAPIENTRY
282 _es_VertexAttrib3f(GLuint indx, GLfloat x, GLfloat y, GLfloat z);
283 
284 void GLAPIENTRY
285 _es_VertexAttrib3fv(GLuint indx, const GLfloat* values);
286 
287 void GLAPIENTRY
288 _es_VertexAttrib4fv(GLuint indx, const GLfloat* values);
289 
290 #ifdef __cplusplus
291 } // extern "C"
292 #endif
293 
294 #endif
295