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 * Current vertex processing mode: fixed function vs. shader.
77 * In reality, fixed function is probably implemented by a shader but that's
78 * not what we care about here.
81 VP_FF
, /**< legacy / fixed function */
82 VP_SHADER
/**< ARB vertex program or GLSL vertex shader */
87 * Get current vertex processing mode (fixed function vs. shader).
89 static inline enum vp_mode
90 get_vp_mode( struct gl_context
*ctx
)
92 if (!ctx
->VertexProgram
._Current
)
94 else if (ctx
->VertexProgram
._Current
== ctx
->VertexProgram
._TnlProgram
)
102 * This is called by glBegin, glDrawArrays and glDrawElements (and
103 * variations of those calls). When we transition from immediate mode
104 * drawing to array drawing we need to invalidate the array state.
106 * glBegin/End builds vertex arrays. Those arrays may look identical
107 * to glDrawArrays arrays except that the position of the elements may
108 * be different. For example, arrays of (position3v, normal3f) vs. arrays
109 * of (normal3f, position3f). So we need to make sure we notify drivers
110 * that arrays may be changing.
113 vbo_draw_method(struct vbo_context
*vbo
, gl_draw_method method
)
115 struct gl_context
*ctx
= vbo
->exec
.ctx
;
117 if (ctx
->Array
.DrawMethod
!= method
) {
120 ctx
->Array
._DrawArrays
= vbo
->exec
.array
.inputs
;
123 ctx
->Array
._DrawArrays
= vbo
->exec
.vtx
.inputs
;
125 case DRAW_DISPLAY_LIST
:
126 ctx
->Array
._DrawArrays
= vbo
->save
.inputs
;
129 unreachable("Bad VBO drawing method");
132 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewArray
;
133 ctx
->Array
.DrawMethod
= method
;
139 * Return if format is integer. The immediate mode commands only emit floats
140 * for non-integer types, thus everything else is integer.
142 static inline GLboolean
143 vbo_attrtype_to_integer_flag(GLenum format
)
150 case GL_UNSIGNED_INT
:
151 case GL_UNSIGNED_INT64_ARB
:
154 unreachable("Bad vertex attribute type");
159 static inline GLboolean
160 vbo_attrtype_to_double_flag(GLenum format
)
165 case GL_UNSIGNED_INT
:
166 case GL_UNSIGNED_INT64_ARB
:
171 unreachable("Bad vertex attribute type");
178 * Return default component values for the given format.
179 * The return type is an array of fi_types, because that's how we declare
180 * the vertex storage : floats , integers or unsigned integers.
182 static inline const fi_type
*
183 vbo_get_default_vals_as_union(GLenum format
)
185 static const GLfloat default_float
[4] = { 0, 0, 0, 1 };
186 static const GLint default_int
[4] = { 0, 0, 0, 1 };
190 return (fi_type
*)default_float
;
192 case GL_UNSIGNED_INT
:
193 return (fi_type
*)default_int
;
195 unreachable("Bad vertex format");
202 * Compute the max number of vertices which can be stored in
203 * a vertex buffer, given the current vertex size, and the amount
204 * of space already used.
206 static inline unsigned
207 vbo_compute_max_verts(const struct vbo_exec_context
*exec
)
209 unsigned n
= (VBO_VERT_BUFFER_SIZE
- exec
->vtx
.buffer_used
) /
210 (exec
->vtx
.vertex_size
* sizeof(GLfloat
));
213 /* Subtract one so we're always sure to have room for an extra
214 * vertex for GL_LINE_LOOP -> GL_LINE_STRIP conversion.
222 vbo_try_prim_conversion(struct _mesa_prim
*p
);
225 vbo_can_merge_prims(const struct _mesa_prim
*p0
, const struct _mesa_prim
*p1
);
228 vbo_merge_prims(struct _mesa_prim
*p0
, const struct _mesa_prim
*p1
);
231 #endif /* VBO_PRIVATE_H */