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.
27 * Types, functions, etc which are private to the VBO module.
35 #include "vbo/vbo_attrib.h"
36 #include "vbo/vbo_exec.h"
37 #include "vbo/vbo_save.h"
38 #include "main/mtypes.h"
46 struct gl_vertex_array currval
[VBO_ATTRIB_MAX
];
48 /** Map VERT_ATTRIB_x to VBO_ATTRIB_y */
49 GLubyte map_vp_none
[VERT_ATTRIB_MAX
];
50 GLubyte map_vp_arb
[VERT_ATTRIB_MAX
];
52 struct vbo_exec_context exec
;
53 struct vbo_save_context save
;
55 /* Callback into the driver. This must always succeed, the driver
56 * is responsible for initiating any fallback actions required:
58 vbo_draw_func draw_prims
;
60 /* Optional callback for indirect draws. This allows multidraws to not be
61 * broken up, as well as for the actual count to be passed in as a separate
64 vbo_indirect_draw_func draw_indirect_prims
;
68 static inline struct vbo_context
*
69 vbo_context(struct gl_context
*ctx
)
71 return ctx
->vbo_context
;
76 * Return VP_x token to indicate whether we're running fixed-function
77 * vertex transformation, an NV vertex program or ARB vertex program/shader.
79 static inline enum vp_mode
80 get_program_mode( struct gl_context
*ctx
)
82 if (!ctx
->VertexProgram
._Current
)
84 else if (ctx
->VertexProgram
._Current
== ctx
->VertexProgram
._TnlProgram
)
92 * This is called by glBegin, glDrawArrays and glDrawElements (and
93 * variations of those calls). When we transition from immediate mode
94 * drawing to array drawing we need to invalidate the array state.
96 * glBegin/End builds vertex arrays. Those arrays may look identical
97 * to glDrawArrays arrays except that the position of the elements may
98 * be different. For example, arrays of (position3v, normal3f) vs. arrays
99 * of (normal3f, position3f). So we need to make sure we notify drivers
100 * that arrays may be changing.
103 vbo_draw_method(struct vbo_context
*vbo
, gl_draw_method method
)
105 struct gl_context
*ctx
= vbo
->exec
.ctx
;
107 if (ctx
->Array
.DrawMethod
!= method
) {
110 ctx
->Array
._DrawArrays
= vbo
->exec
.array
.inputs
;
113 ctx
->Array
._DrawArrays
= vbo
->exec
.vtx
.inputs
;
115 case DRAW_DISPLAY_LIST
:
116 ctx
->Array
._DrawArrays
= vbo
->save
.inputs
;
119 unreachable("Bad VBO drawing method");
122 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewArray
;
123 ctx
->Array
.DrawMethod
= method
;
129 * Return if format is integer. The immediate mode commands only emit floats
130 * for non-integer types, thus everything else is integer.
132 static inline GLboolean
133 vbo_attrtype_to_integer_flag(GLenum format
)
140 case GL_UNSIGNED_INT
:
141 case GL_UNSIGNED_INT64_ARB
:
144 unreachable("Bad vertex attribute type");
149 static inline GLboolean
150 vbo_attrtype_to_double_flag(GLenum format
)
155 case GL_UNSIGNED_INT
:
156 case GL_UNSIGNED_INT64_ARB
:
161 unreachable("Bad vertex attribute type");
168 * Return default component values for the given format.
169 * The return type is an array of fi_types, because that's how we declare
170 * the vertex storage : floats , integers or unsigned integers.
172 static inline const fi_type
*
173 vbo_get_default_vals_as_union(GLenum format
)
175 static const GLfloat default_float
[4] = { 0, 0, 0, 1 };
176 static const GLint default_int
[4] = { 0, 0, 0, 1 };
180 return (fi_type
*)default_float
;
182 case GL_UNSIGNED_INT
:
183 return (fi_type
*)default_int
;
185 unreachable("Bad vertex format");
192 * Compute the max number of vertices which can be stored in
193 * a vertex buffer, given the current vertex size, and the amount
194 * of space already used.
196 static inline unsigned
197 vbo_compute_max_verts(const struct vbo_exec_context
*exec
)
199 unsigned n
= (VBO_VERT_BUFFER_SIZE
- exec
->vtx
.buffer_used
) /
200 (exec
->vtx
.vertex_size
* sizeof(GLfloat
));
203 /* Subtract one so we're always sure to have room for an extra
204 * vertex for GL_LINE_LOOP -> GL_LINE_STRIP conversion.
212 vbo_try_prim_conversion(struct _mesa_prim
*p
);
215 vbo_can_merge_prims(const struct _mesa_prim
*p0
, const struct _mesa_prim
*p1
);
218 vbo_merge_prims(struct _mesa_prim
*p0
, const struct _mesa_prim
*p1
);
221 #endif /* VBO_PRIVATE_H */