vbo: create a few utility functions for merging primitives
[mesa.git] / src / mesa / vbo / vbo.h
1 /*
2 * mesa 3-D graphics library
3 * Version: 6.5
4 *
5 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26 /**
27 * \file vbo_context.h
28 * \brief VBO builder module datatypes and definitions.
29 * \author Keith Whitwell
30 */
31
32
33 #ifndef _VBO_H
34 #define _VBO_H
35
36 #include <stdbool.h>
37 #include "main/glheader.h"
38
39 struct gl_client_array;
40 struct gl_context;
41 struct gl_transform_feedback_object;
42
43 struct _mesa_prim {
44 GLuint mode:8; /**< GL_POINTS, GL_LINES, GL_QUAD_STRIP, etc */
45 GLuint indexed:1;
46 GLuint begin:1;
47 GLuint end:1;
48 GLuint weak:1;
49 GLuint no_current_update:1;
50 GLuint pad:19;
51
52 GLuint start;
53 GLuint count;
54 GLint basevertex;
55 GLuint num_instances;
56 GLuint base_instance;
57 };
58
59 /* Would like to call this a "vbo_index_buffer", but this would be
60 * confusing as the indices are not neccessarily yet in a non-null
61 * buffer object.
62 */
63 struct _mesa_index_buffer {
64 GLuint count;
65 GLenum type;
66 struct gl_buffer_object *obj;
67 const void *ptr;
68 };
69
70
71
72 GLboolean _vbo_CreateContext( struct gl_context *ctx );
73 void _vbo_DestroyContext( struct gl_context *ctx );
74 void _vbo_InvalidateState( struct gl_context *ctx, GLuint new_state );
75
76
77 void
78 vbo_initialize_exec_dispatch(const struct gl_context *ctx,
79 struct _glapi_table *exec);
80
81 void
82 vbo_initialize_save_dispatch(const struct gl_context *ctx,
83 struct _glapi_table *exec);
84
85
86 typedef void (*vbo_draw_func)( struct gl_context *ctx,
87 const struct _mesa_prim *prims,
88 GLuint nr_prims,
89 const struct _mesa_index_buffer *ib,
90 GLboolean index_bounds_valid,
91 GLuint min_index,
92 GLuint max_index,
93 struct gl_transform_feedback_object *tfb_vertcount );
94
95
96
97
98 /* Utility function to cope with various constraints on tnl modules or
99 * hardware. This can be used to split an incoming set of arrays and
100 * primitives against the following constraints:
101 * - Maximum number of indices in index buffer.
102 * - Maximum number of vertices referenced by index buffer.
103 * - Maximum hardware vertex buffer size.
104 */
105 struct split_limits {
106 GLuint max_verts;
107 GLuint max_indices;
108 GLuint max_vb_size; /* bytes */
109 };
110
111
112 void vbo_split_prims( struct gl_context *ctx,
113 const struct gl_client_array *arrays[],
114 const struct _mesa_prim *prim,
115 GLuint nr_prims,
116 const struct _mesa_index_buffer *ib,
117 GLuint min_index,
118 GLuint max_index,
119 vbo_draw_func draw,
120 const struct split_limits *limits );
121
122
123 /* Helpers for dealing translating away non-zero min_index.
124 */
125 GLboolean vbo_all_varyings_in_vbos( const struct gl_client_array *arrays[] );
126 GLboolean vbo_any_varyings_in_vbos( const struct gl_client_array *arrays[] );
127
128 void vbo_rebase_prims( struct gl_context *ctx,
129 const struct gl_client_array *arrays[],
130 const struct _mesa_prim *prim,
131 GLuint nr_prims,
132 const struct _mesa_index_buffer *ib,
133 GLuint min_index,
134 GLuint max_index,
135 vbo_draw_func draw );
136
137 static inline int
138 vbo_sizeof_ib_type(GLenum type)
139 {
140 switch (type) {
141 case GL_UNSIGNED_INT:
142 return sizeof(GLuint);
143 case GL_UNSIGNED_SHORT:
144 return sizeof(GLushort);
145 case GL_UNSIGNED_BYTE:
146 return sizeof(GLubyte);
147 default:
148 assert(!"unsupported index data type");
149 /* In case assert is turned off */
150 return 0;
151 }
152 }
153
154 void
155 vbo_get_minmax_indices(struct gl_context *ctx, const struct _mesa_prim *prim,
156 const struct _mesa_index_buffer *ib,
157 GLuint *min_index, GLuint *max_index, GLuint nr_prims);
158
159 void vbo_use_buffer_objects(struct gl_context *ctx);
160
161 void vbo_always_unmap_buffers(struct gl_context *ctx);
162
163 void vbo_set_draw_func(struct gl_context *ctx, vbo_draw_func func);
164
165 void vbo_check_buffers_are_unmapped(struct gl_context *ctx);
166
167 void vbo_bind_arrays(struct gl_context *ctx);
168
169 size_t
170 vbo_count_tessellated_primitives(GLenum mode, GLuint count,
171 GLuint num_instances);
172
173 void
174 vbo_try_prim_conversion(struct _mesa_prim *p);
175
176 bool
177 vbo_can_merge_prims(const struct _mesa_prim *p0, const struct _mesa_prim *p1);
178
179 void
180 vbo_merge_prims(struct _mesa_prim *p0, const struct _mesa_prim *p1);
181
182 void
183 vbo_sw_primitive_restart(struct gl_context *ctx,
184 const struct _mesa_prim *prim,
185 GLuint nr_prims,
186 const struct _mesa_index_buffer *ib);
187
188 void GLAPIENTRY
189 _es_Color4f(GLfloat r, GLfloat g, GLfloat b, GLfloat a);
190
191 void GLAPIENTRY
192 _es_Normal3f(GLfloat x, GLfloat y, GLfloat z);
193
194 void GLAPIENTRY
195 _es_MultiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q);
196
197 void GLAPIENTRY
198 _es_Materialfv(GLenum face, GLenum pname, const GLfloat *params);
199
200 void GLAPIENTRY
201 _es_Materialf(GLenum face, GLenum pname, GLfloat param);
202
203 void GLAPIENTRY
204 _es_VertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
205
206 void GLAPIENTRY
207 _es_VertexAttrib1f(GLuint indx, GLfloat x);
208
209 void GLAPIENTRY
210 _es_VertexAttrib1fv(GLuint indx, const GLfloat* values);
211
212 void GLAPIENTRY
213 _es_VertexAttrib2f(GLuint indx, GLfloat x, GLfloat y);
214
215 void GLAPIENTRY
216 _es_VertexAttrib2fv(GLuint indx, const GLfloat* values);
217
218 void GLAPIENTRY
219 _es_VertexAttrib3f(GLuint indx, GLfloat x, GLfloat y, GLfloat z);
220
221 void GLAPIENTRY
222 _es_VertexAttrib3fv(GLuint indx, const GLfloat* values);
223
224 void GLAPIENTRY
225 _es_VertexAttrib4fv(GLuint indx, const GLfloat* values);
226
227 #endif