• 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 #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    struct {
105       /* Multi draw where the mode can vary between draws. */
106       struct pipe_draw_info info;
107       struct pipe_draw_start_count_bias draw[VBO_MAX_PRIM];
108       GLubyte mode[VBO_MAX_PRIM];            /**< primitive modes per draw */
109       struct vbo_markers markers[VBO_MAX_PRIM];
110       unsigned prim_count;
111 
112       struct gl_buffer_object *bufferobj;
113 
114       GLuint vertex_size;       /* in dwords */
115       GLuint vertex_size_no_pos;
116 
117       fi_type *buffer_map;
118       fi_type *buffer_ptr;              /* cursor, points into buffer */
119       GLuint   buffer_used;             /* in bytes */
120       unsigned buffer_offset;           /* only for persistent mappings */
121       fi_type vertex[VBO_ATTRIB_MAX*4]; /* current vertex */
122 
123       GLuint vert_count;   /**< Number of vertices currently in buffer */
124       GLuint max_vert;     /**< Max number of vertices allowed in buffer */
125       struct vbo_exec_copied_vtx copied;
126 
127       GLbitfield64 enabled;             /**< mask of enabled vbo arrays. */
128 
129       /* Keep these packed in a structure for faster access. */
130       struct {
131          GLenum16 type;       /**< GL_FLOAT, GL_DOUBLE, GL_INT, etc */
132          GLubyte active_size; /**< number of components, but can shrink */
133          GLubyte size;        /**< number of components (1..4) */
134       } attr[VBO_ATTRIB_MAX];
135 
136       /** pointers into the current 'vertex' array, declared above */
137       fi_type *attrptr[VBO_ATTRIB_MAX];
138    } vtx;
139 
140    struct {
141       GLboolean recalculate_maps;
142       struct vbo_exec_eval1_map map1[VERT_ATTRIB_MAX];
143       struct vbo_exec_eval2_map map2[VERT_ATTRIB_MAX];
144    } eval;
145 
146 #ifndef NDEBUG
147    GLint flush_call_depth;
148 #endif
149 };
150 
151 
152 struct vbo_save_context {
153    GLbitfield64 enabled; /**< mask of enabled vbo arrays. */
154    GLubyte attrsz[VBO_ATTRIB_MAX];  /**< 1, 2, 3 or 4 */
155    GLenum16 attrtype[VBO_ATTRIB_MAX];  /**< GL_FLOAT, GL_INT, etc */
156    GLubyte active_sz[VBO_ATTRIB_MAX];  /**< 1, 2, 3 or 4 */
157    GLuint vertex_size;  /**< size in GLfloats */
158    struct gl_vertex_array_object *VAO[VP_MODE_MAX];
159 
160    struct vbo_save_vertex_store *vertex_store;
161    struct vbo_save_primitive_store *prim_store;
162    struct gl_buffer_object *current_bo;
163    unsigned current_bo_bytes_used;
164 
165    fi_type vertex[VBO_ATTRIB_MAX*4];	   /* current values */
166    fi_type *attrptr[VBO_ATTRIB_MAX];
167 
168    struct {
169       fi_type *buffer;
170       GLuint nr;
171    } copied;
172 
173    fi_type *current[VBO_ATTRIB_MAX]; /* points into ctx->ListState */
174    GLubyte *currentsz[VBO_ATTRIB_MAX];
175 
176    GLboolean dangling_attr_ref;
177    GLboolean out_of_memory;  /**< True if last VBO allocation failed */
178    bool no_current_update;
179 };
180 
181 GLboolean
182 _mesa_using_noop_vtxfmt(const struct _glapi_table *dispatch);
183 
184 GLboolean
185 _vbo_CreateContext(struct gl_context *ctx);
186 
187 void
188 _vbo_DestroyContext(struct gl_context *ctx);
189 
190 void
191 vbo_install_exec_vtxfmt(struct gl_context *ctx);
192 
193 void
194 vbo_install_hw_select_begin_end(struct gl_context *ctx);
195 
196 void
197 vbo_install_exec_vtxfmt_noop(struct gl_context *ctx);
198 
199 void
200 vbo_install_save_vtxfmt_noop(struct gl_context *ctx);
201 
202 void
203 vbo_exec_update_eval_maps(struct gl_context *ctx);
204 
205 void
206 vbo_exec_FlushVertices(struct gl_context *ctx, GLuint flags);
207 
208 void
209 vbo_save_SaveFlushVertices(struct gl_context *ctx);
210 
211 void
212 vbo_save_NotifyBegin(struct gl_context *ctx, GLenum mode,
213                      bool no_current_update);
214 
215 void
216 vbo_save_NewList(struct gl_context *ctx, GLuint list, GLenum mode);
217 
218 void
219 vbo_save_EndList(struct gl_context *ctx);
220 
221 void
222 vbo_delete_minmax_cache(struct gl_buffer_object *bufferObj);
223 
224 void
225 vbo_get_minmax_index_mapped(unsigned count, unsigned index_size,
226                             unsigned restartIndex, bool restart,
227                             const void *indices,
228                             unsigned *min_index, unsigned *max_index);
229 
230 void
231 vbo_get_minmax_indices(struct gl_context *ctx, const struct _mesa_prim *prim,
232                        const struct _mesa_index_buffer *ib,
233                        GLuint *min_index, GLuint *max_index, GLuint nr_prims,
234                        bool primitive_restart,
235                        unsigned restart_index);
236 
237 bool
238 vbo_get_minmax_indices_gallium(struct gl_context *ctx,
239                                struct pipe_draw_info *info,
240                                const struct pipe_draw_start_count_bias *draws,
241                                unsigned num_draws);
242 
243 const struct gl_array_attributes*
244 _vbo_current_attrib(const struct gl_context *ctx, gl_vert_attrib attr);
245 
246 void GLAPIENTRY
247 _es_Color4f(GLfloat r, GLfloat g, GLfloat b, GLfloat a);
248 
249 void GLAPIENTRY
250 _es_Normal3f(GLfloat x, GLfloat y, GLfloat z);
251 
252 void GLAPIENTRY
253 _es_MultiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q);
254 
255 void GLAPIENTRY
256 _es_Materialfv(GLenum face, GLenum pname, const GLfloat *params);
257 
258 void GLAPIENTRY
259 _es_Materialf(GLenum face, GLenum pname, GLfloat param);
260 
261 #ifdef __cplusplus
262 } // extern "C"
263 #endif
264 
265 #endif
266