2 * mesa 3-D graphics library
4 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
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:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
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.
26 * \brief Public interface to the VBO module
27 * \author Keith Whitwell
35 #include "main/glheader.h"
37 #include "main/draw.h"
38 #include "main/macros.h"
39 #include "vbo_attrib.h"
49 * Max number of primitives (number of glBegin/End pairs) per VBO.
51 #define VBO_MAX_PRIM 64
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.
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
;
67 struct vbo_exec_eval1_map
{
68 struct gl_1d_map
*map
;
72 struct vbo_exec_eval2_map
{
73 struct gl_2d_map
*map
;
77 struct vbo_exec_copied_vtx
{
78 fi_type buffer
[VBO_ATTRIB_MAX
* 4 * VBO_MAX_COPIED_VERTS
];
82 struct vbo_exec_context
84 struct gl_context
*ctx
;
85 GLvertexformat vtxfmt
;
86 GLvertexformat vtxfmt_noop
;
89 struct gl_buffer_object
*bufferobj
;
91 GLuint vertex_size
; /* in dwords */
92 GLuint vertex_size_no_pos
;
94 struct _mesa_prim prim
[VBO_MAX_PRIM
];
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 */
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
;
107 GLbitfield64 enabled
; /**< mask of enabled vbo arrays. */
109 /* Keep these packed in a structure for faster access. */
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
];
116 /** pointers into the current 'vertex' array, declared above */
117 fi_type
*attrptr
[VBO_ATTRIB_MAX
];
121 GLboolean recalculate_maps
;
122 struct vbo_exec_eval1_map map1
[VERT_ATTRIB_MAX
];
123 struct vbo_exec_eval2_map map2
[VERT_ATTRIB_MAX
];
127 GLint flush_call_depth
;
131 struct vbo_save_copied_vtx
{
132 fi_type buffer
[VBO_ATTRIB_MAX
* 4 * VBO_MAX_COPIED_VERTS
];
136 struct vbo_save_context
{
137 struct gl_context
*ctx
;
138 GLvertexformat vtxfmt
;
139 GLvertexformat vtxfmt_noop
; /**< Used if out_of_memory is true */
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
];
148 GLboolean out_of_memory
; /**< True if last VBO allocation failed */
150 GLbitfield replay_flags
;
152 struct _mesa_prim
*prims
;
153 GLuint prim_count
, prim_max
;
155 bool no_current_update
;
157 struct vbo_save_vertex_store
*vertex_store
;
158 struct vbo_save_primitive_store
*prim_store
;
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
];
166 GLboolean dangling_attr_ref
;
168 GLuint opcode_vertex_list
;
170 struct vbo_save_copied_vtx copied
;
172 fi_type
*current
[VBO_ATTRIB_MAX
]; /* points into ctx->ListState */
173 GLubyte
*currentsz
[VBO_ATTRIB_MAX
];
177 _vbo_CreateContext(struct gl_context
*ctx
, bool use_buffer_objects
);
180 _vbo_DestroyContext(struct gl_context
*ctx
);
183 vbo_exec_update_eval_maps(struct gl_context
*ctx
);
186 _vbo_install_exec_vtxfmt(struct gl_context
*ctx
);
189 vbo_initialize_exec_dispatch(const struct gl_context
*ctx
,
190 struct _glapi_table
*exec
);
193 vbo_initialize_save_dispatch(const struct gl_context
*ctx
,
194 struct _glapi_table
*exec
);
197 vbo_exec_FlushVertices(struct gl_context
*ctx
, GLuint flags
);
200 vbo_save_SaveFlushVertices(struct gl_context
*ctx
);
203 vbo_save_NotifyBegin(struct gl_context
*ctx
, GLenum mode
,
204 bool no_current_update
);
207 vbo_save_NewList(struct gl_context
*ctx
, GLuint list
, GLenum mode
);
210 vbo_save_EndList(struct gl_context
*ctx
);
213 vbo_save_BeginCallList(struct gl_context
*ctx
, struct gl_display_list
*list
);
216 vbo_save_EndCallList(struct gl_context
*ctx
);
220 vbo_delete_minmax_cache(struct gl_buffer_object
*bufferObj
);
223 vbo_get_minmax_index_mapped(unsigned count
, unsigned index_size
,
224 unsigned restartIndex
, bool restart
,
226 unsigned *min_index
, unsigned *max_index
);
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
);
234 vbo_sw_primitive_restart(struct gl_context
*ctx
,
235 const struct _mesa_prim
*prim
,
237 const struct _mesa_index_buffer
*ib
,
238 GLuint num_instances
, GLuint base_instance
,
239 struct gl_buffer_object
*indirect
,
240 GLsizeiptr indirect_offset
);
243 const struct gl_array_attributes
*
244 _vbo_current_attrib(const struct gl_context
*ctx
, gl_vert_attrib attr
);
247 const struct gl_vertex_buffer_binding
*
248 _vbo_current_binding(const struct gl_context
*ctx
);
252 _es_Color4f(GLfloat r
, GLfloat g
, GLfloat b
, GLfloat a
);
255 _es_Normal3f(GLfloat x
, GLfloat y
, GLfloat z
);
258 _es_MultiTexCoord4f(GLenum target
, GLfloat s
, GLfloat t
, GLfloat r
, GLfloat q
);
261 _es_Materialfv(GLenum face
, GLenum pname
, const GLfloat
*params
);
264 _es_Materialf(GLenum face
, GLenum pname
, GLfloat param
);
267 _es_VertexAttrib4f(GLuint index
, GLfloat x
, GLfloat y
, GLfloat z
, GLfloat w
);
270 _es_VertexAttrib1f(GLuint indx
, GLfloat x
);
273 _es_VertexAttrib1fv(GLuint indx
, const GLfloat
* values
);
276 _es_VertexAttrib2f(GLuint indx
, GLfloat x
, GLfloat y
);
279 _es_VertexAttrib2fv(GLuint indx
, const GLfloat
* values
);
282 _es_VertexAttrib3f(GLuint indx
, GLfloat x
, GLfloat y
, GLfloat z
);
285 _es_VertexAttrib3fv(GLuint indx
, const GLfloat
* values
);
288 _es_VertexAttrib4fv(GLuint indx
, const GLfloat
* values
);