meson: fix missing dependencies
[mesa.git] / src / mesa / vbo / vbo_private.h
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 /**
27 * Types, functions, etc which are private to the VBO module.
28 */
29
30
31 #ifndef VBO_PRIVATE_H
32 #define VBO_PRIVATE_H
33
34
35 #include "vbo/vbo_attrib.h"
36 #include "vbo/vbo_exec.h"
37 #include "vbo/vbo_save.h"
38 #include "main/mtypes.h"
39
40
41 struct _glapi_table;
42 struct _mesa_prim;
43
44
45 struct vbo_context {
46 struct gl_vertex_array currval[VBO_ATTRIB_MAX];
47
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];
51
52 struct vbo_exec_context exec;
53 struct vbo_save_context save;
54
55 /* Callback into the driver. This must always succeed, the driver
56 * is responsible for initiating any fallback actions required:
57 */
58 vbo_draw_func draw_prims;
59
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
62 * indirect parameter.
63 */
64 vbo_indirect_draw_func draw_indirect_prims;
65 };
66
67
68 static inline struct vbo_context *
69 vbo_context(struct gl_context *ctx)
70 {
71 return ctx->vbo_context;
72 }
73
74
75 /**
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.
78 */
79 static inline enum vp_mode
80 get_program_mode( struct gl_context *ctx )
81 {
82 if (!ctx->VertexProgram._Current)
83 return VP_NONE;
84 else if (ctx->VertexProgram._Current == ctx->VertexProgram._TnlProgram)
85 return VP_NONE;
86 else
87 return VP_ARB;
88 }
89
90
91 /**
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.
95 *
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.
101 */
102 static inline void
103 vbo_draw_method(struct vbo_context *vbo, gl_draw_method method)
104 {
105 struct gl_context *ctx = vbo->exec.ctx;
106
107 if (ctx->Array.DrawMethod != method) {
108 switch (method) {
109 case DRAW_ARRAYS:
110 ctx->Array._DrawArrays = vbo->exec.array.inputs;
111 break;
112 case DRAW_BEGIN_END:
113 ctx->Array._DrawArrays = vbo->exec.vtx.inputs;
114 break;
115 case DRAW_DISPLAY_LIST:
116 ctx->Array._DrawArrays = vbo->save.inputs;
117 break;
118 default:
119 unreachable("Bad VBO drawing method");
120 }
121
122 ctx->NewDriverState |= ctx->DriverFlags.NewArray;
123 ctx->Array.DrawMethod = method;
124 }
125 }
126
127
128 /**
129 * Return if format is integer. The immediate mode commands only emit floats
130 * for non-integer types, thus everything else is integer.
131 */
132 static inline GLboolean
133 vbo_attrtype_to_integer_flag(GLenum format)
134 {
135 switch (format) {
136 case GL_FLOAT:
137 case GL_DOUBLE:
138 return GL_FALSE;
139 case GL_INT:
140 case GL_UNSIGNED_INT:
141 case GL_UNSIGNED_INT64_ARB:
142 return GL_TRUE;
143 default:
144 unreachable("Bad vertex attribute type");
145 return GL_FALSE;
146 }
147 }
148
149 static inline GLboolean
150 vbo_attrtype_to_double_flag(GLenum format)
151 {
152 switch (format) {
153 case GL_FLOAT:
154 case GL_INT:
155 case GL_UNSIGNED_INT:
156 case GL_UNSIGNED_INT64_ARB:
157 return GL_FALSE;
158 case GL_DOUBLE:
159 return GL_TRUE;
160 default:
161 unreachable("Bad vertex attribute type");
162 return GL_FALSE;
163 }
164 }
165
166
167 /**
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.
171 */
172 static inline const fi_type *
173 vbo_get_default_vals_as_union(GLenum format)
174 {
175 static const GLfloat default_float[4] = { 0, 0, 0, 1 };
176 static const GLint default_int[4] = { 0, 0, 0, 1 };
177
178 switch (format) {
179 case GL_FLOAT:
180 return (fi_type *)default_float;
181 case GL_INT:
182 case GL_UNSIGNED_INT:
183 return (fi_type *)default_int;
184 default:
185 unreachable("Bad vertex format");
186 return NULL;
187 }
188 }
189
190
191 /**
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.
195 */
196 static inline unsigned
197 vbo_compute_max_verts(const struct vbo_exec_context *exec)
198 {
199 unsigned n = (VBO_VERT_BUFFER_SIZE - exec->vtx.buffer_used) /
200 (exec->vtx.vertex_size * sizeof(GLfloat));
201 if (n == 0)
202 return 0;
203 /* Subtract one so we're always sure to have room for an extra
204 * vertex for GL_LINE_LOOP -> GL_LINE_STRIP conversion.
205 */
206 n--;
207 return n;
208 }
209
210
211 void
212 vbo_try_prim_conversion(struct _mesa_prim *p);
213
214 bool
215 vbo_can_merge_prims(const struct _mesa_prim *p0, const struct _mesa_prim *p1);
216
217 void
218 vbo_merge_prims(struct _mesa_prim *p0, const struct _mesa_prim *p1);
219
220
221 #endif /* VBO_PRIVATE_H */