vbo.h revision af69d88d
17117f1b4Smrg/*
27117f1b4Smrg * mesa 3-D graphics library
37117f1b4Smrg *
47117f1b4Smrg * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
57117f1b4Smrg *
67117f1b4Smrg * Permission is hereby granted, free of charge, to any person obtaining a
77117f1b4Smrg * copy of this software and associated documentation files (the "Software"),
87117f1b4Smrg * to deal in the Software without restriction, including without limitation
97117f1b4Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
107117f1b4Smrg * and/or sell copies of the Software, and to permit persons to whom the
117117f1b4Smrg * Software is furnished to do so, subject to the following conditions:
127117f1b4Smrg *
137117f1b4Smrg * The above copyright notice and this permission notice shall be included
147117f1b4Smrg * in all copies or substantial portions of the Software.
157117f1b4Smrg *
167117f1b4Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
177117f1b4Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
187117f1b4Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19af69d88dSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20af69d88dSmrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21af69d88dSmrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22af69d88dSmrg * OTHER DEALINGS IN THE SOFTWARE.
237117f1b4Smrg */
247117f1b4Smrg
257117f1b4Smrg/**
267117f1b4Smrg * \file vbo_context.h
277117f1b4Smrg * \brief VBO builder module datatypes and definitions.
287117f1b4Smrg * \author Keith Whitwell
297117f1b4Smrg */
307117f1b4Smrg
317117f1b4Smrg
327117f1b4Smrg#ifndef _VBO_H
337117f1b4Smrg#define _VBO_H
347117f1b4Smrg
35af69d88dSmrg#include <stdbool.h>
363464ebd5Sriastradh#include "main/glheader.h"
373464ebd5Sriastradh
383464ebd5Sriastradhstruct gl_client_array;
393464ebd5Sriastradhstruct gl_context;
40af69d88dSmrgstruct gl_transform_feedback_object;
417117f1b4Smrg
427117f1b4Smrgstruct _mesa_prim {
433464ebd5Sriastradh   GLuint mode:8;    /**< GL_POINTS, GL_LINES, GL_QUAD_STRIP, etc */
447117f1b4Smrg   GLuint indexed:1;
457117f1b4Smrg   GLuint begin:1;
467117f1b4Smrg   GLuint end:1;
477117f1b4Smrg   GLuint weak:1;
483464ebd5Sriastradh   GLuint no_current_update:1;
49af69d88dSmrg   GLuint is_indirect:1;
50af69d88dSmrg   GLuint pad:18;
517117f1b4Smrg
527117f1b4Smrg   GLuint start;
537117f1b4Smrg   GLuint count;
544a49301eSmrg   GLint basevertex;
55af69d88dSmrg   GLuint num_instances;
56af69d88dSmrg   GLuint base_instance;
57af69d88dSmrg
58af69d88dSmrg   GLsizeiptr indirect_offset;
597117f1b4Smrg};
607117f1b4Smrg
617117f1b4Smrg/* Would like to call this a "vbo_index_buffer", but this would be
627117f1b4Smrg * confusing as the indices are not neccessarily yet in a non-null
637117f1b4Smrg * buffer object.
647117f1b4Smrg */
657117f1b4Smrgstruct _mesa_index_buffer {
667117f1b4Smrg   GLuint count;
677117f1b4Smrg   GLenum type;
687117f1b4Smrg   struct gl_buffer_object *obj;
697117f1b4Smrg   const void *ptr;
707117f1b4Smrg};
717117f1b4Smrg
727117f1b4Smrg
737117f1b4Smrg
743464ebd5SriastradhGLboolean _vbo_CreateContext( struct gl_context *ctx );
753464ebd5Sriastradhvoid _vbo_DestroyContext( struct gl_context *ctx );
763464ebd5Sriastradhvoid _vbo_InvalidateState( struct gl_context *ctx, GLuint new_state );
777117f1b4Smrg
787117f1b4Smrg
79af69d88dSmrgvoid
80af69d88dSmrgvbo_initialize_exec_dispatch(const struct gl_context *ctx,
81af69d88dSmrg                             struct _glapi_table *exec);
82af69d88dSmrg
83af69d88dSmrgvoid
84af69d88dSmrgvbo_initialize_save_dispatch(const struct gl_context *ctx,
85af69d88dSmrg                             struct _glapi_table *exec);
86af69d88dSmrg
87af69d88dSmrg
883464ebd5Sriastradhtypedef void (*vbo_draw_func)( struct gl_context *ctx,
897117f1b4Smrg			       const struct _mesa_prim *prims,
907117f1b4Smrg			       GLuint nr_prims,
917117f1b4Smrg			       const struct _mesa_index_buffer *ib,
924a49301eSmrg			       GLboolean index_bounds_valid,
937117f1b4Smrg			       GLuint min_index,
94af69d88dSmrg			       GLuint max_index,
95af69d88dSmrg			       struct gl_transform_feedback_object *tfb_vertcount,
96af69d88dSmrg			       struct gl_buffer_object *indirect );
977117f1b4Smrg
987117f1b4Smrg
997117f1b4Smrg
1007117f1b4Smrg
1017117f1b4Smrg/* Utility function to cope with various constraints on tnl modules or
1027117f1b4Smrg * hardware.  This can be used to split an incoming set of arrays and
1037117f1b4Smrg * primitives against the following constraints:
1047117f1b4Smrg *    - Maximum number of indices in index buffer.
1057117f1b4Smrg *    - Maximum number of vertices referenced by index buffer.
1067117f1b4Smrg *    - Maximum hardware vertex buffer size.
1077117f1b4Smrg */
1087117f1b4Smrgstruct split_limits {
1097117f1b4Smrg   GLuint max_verts;
1107117f1b4Smrg   GLuint max_indices;
1117117f1b4Smrg   GLuint max_vb_size;		/* bytes */
1127117f1b4Smrg};
1137117f1b4Smrg
1147117f1b4Smrg
1153464ebd5Sriastradhvoid vbo_split_prims( struct gl_context *ctx,
1167117f1b4Smrg		      const struct gl_client_array *arrays[],
1177117f1b4Smrg		      const struct _mesa_prim *prim,
1187117f1b4Smrg		      GLuint nr_prims,
1197117f1b4Smrg		      const struct _mesa_index_buffer *ib,
1207117f1b4Smrg		      GLuint min_index,
1217117f1b4Smrg		      GLuint max_index,
1227117f1b4Smrg		      vbo_draw_func draw,
1237117f1b4Smrg		      const struct split_limits *limits );
1247117f1b4Smrg
1257117f1b4Smrg
1267117f1b4Smrg/* Helpers for dealing translating away non-zero min_index.
1277117f1b4Smrg */
1287117f1b4SmrgGLboolean vbo_all_varyings_in_vbos( const struct gl_client_array *arrays[] );
1293464ebd5SriastradhGLboolean vbo_any_varyings_in_vbos( const struct gl_client_array *arrays[] );
1307117f1b4Smrg
1313464ebd5Sriastradhvoid vbo_rebase_prims( struct gl_context *ctx,
1327117f1b4Smrg		       const struct gl_client_array *arrays[],
1337117f1b4Smrg		       const struct _mesa_prim *prim,
1347117f1b4Smrg		       GLuint nr_prims,
1357117f1b4Smrg		       const struct _mesa_index_buffer *ib,
1367117f1b4Smrg		       GLuint min_index,
1377117f1b4Smrg		       GLuint max_index,
1387117f1b4Smrg		       vbo_draw_func draw );
139af69d88dSmrg
140af69d88dSmrgstatic inline int
141af69d88dSmrgvbo_sizeof_ib_type(GLenum type)
142af69d88dSmrg{
143af69d88dSmrg   switch (type) {
144af69d88dSmrg   case GL_UNSIGNED_INT:
145af69d88dSmrg      return sizeof(GLuint);
146af69d88dSmrg   case GL_UNSIGNED_SHORT:
147af69d88dSmrg      return sizeof(GLushort);
148af69d88dSmrg   case GL_UNSIGNED_BYTE:
149af69d88dSmrg      return sizeof(GLubyte);
150af69d88dSmrg   default:
151af69d88dSmrg      assert(!"unsupported index data type");
152af69d88dSmrg      /* In case assert is turned off */
153af69d88dSmrg      return 0;
154af69d88dSmrg   }
155af69d88dSmrg}
156af69d88dSmrg
1574a49301eSmrgvoid
158af69d88dSmrgvbo_get_minmax_indices(struct gl_context *ctx, const struct _mesa_prim *prim,
159af69d88dSmrg                       const struct _mesa_index_buffer *ib,
160af69d88dSmrg                       GLuint *min_index, GLuint *max_index, GLuint nr_prims);
1617117f1b4Smrg
1623464ebd5Sriastradhvoid vbo_use_buffer_objects(struct gl_context *ctx);
1633464ebd5Sriastradh
1643464ebd5Sriastradhvoid vbo_always_unmap_buffers(struct gl_context *ctx);
1653464ebd5Sriastradh
1663464ebd5Sriastradhvoid vbo_set_draw_func(struct gl_context *ctx, vbo_draw_func func);
1673464ebd5Sriastradh
1683464ebd5Sriastradhvoid vbo_check_buffers_are_unmapped(struct gl_context *ctx);
1693464ebd5Sriastradh
170af69d88dSmrgvoid vbo_bind_arrays(struct gl_context *ctx);
171af69d88dSmrg
172af69d88dSmrgsize_t
173af69d88dSmrgvbo_count_tessellated_primitives(GLenum mode, GLuint count,
174af69d88dSmrg                                 GLuint num_instances);
175af69d88dSmrg
176af69d88dSmrgvoid
177af69d88dSmrgvbo_try_prim_conversion(struct _mesa_prim *p);
178af69d88dSmrg
179af69d88dSmrgbool
180af69d88dSmrgvbo_can_merge_prims(const struct _mesa_prim *p0, const struct _mesa_prim *p1);
181af69d88dSmrg
182af69d88dSmrgvoid
183af69d88dSmrgvbo_merge_prims(struct _mesa_prim *p0, const struct _mesa_prim *p1);
184af69d88dSmrg
185af69d88dSmrgvoid
186af69d88dSmrgvbo_sw_primitive_restart(struct gl_context *ctx,
187af69d88dSmrg                         const struct _mesa_prim *prim,
188af69d88dSmrg                         GLuint nr_prims,
189af69d88dSmrg                         const struct _mesa_index_buffer *ib,
190af69d88dSmrg                         struct gl_buffer_object *indirect);
1913464ebd5Sriastradh
1923464ebd5Sriastradhvoid GLAPIENTRY
1933464ebd5Sriastradh_es_Color4f(GLfloat r, GLfloat g, GLfloat b, GLfloat a);
1943464ebd5Sriastradh
1953464ebd5Sriastradhvoid GLAPIENTRY
1963464ebd5Sriastradh_es_Normal3f(GLfloat x, GLfloat y, GLfloat z);
1973464ebd5Sriastradh
1983464ebd5Sriastradhvoid GLAPIENTRY
1993464ebd5Sriastradh_es_MultiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q);
200c1f859d4Smrg
2013464ebd5Sriastradhvoid GLAPIENTRY
2023464ebd5Sriastradh_es_Materialfv(GLenum face, GLenum pname, const GLfloat *params);
203c1f859d4Smrg
2043464ebd5Sriastradhvoid GLAPIENTRY
2053464ebd5Sriastradh_es_Materialf(GLenum face, GLenum pname, GLfloat param);
2064a49301eSmrg
2073464ebd5Sriastradhvoid GLAPIENTRY
2083464ebd5Sriastradh_es_VertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
2093464ebd5Sriastradh
2103464ebd5Sriastradhvoid GLAPIENTRY
2113464ebd5Sriastradh_es_VertexAttrib1f(GLuint indx, GLfloat x);
2123464ebd5Sriastradh
2133464ebd5Sriastradhvoid GLAPIENTRY
2143464ebd5Sriastradh_es_VertexAttrib1fv(GLuint indx, const GLfloat* values);
2154a49301eSmrg
2164a49301eSmrgvoid GLAPIENTRY
2173464ebd5Sriastradh_es_VertexAttrib2f(GLuint indx, GLfloat x, GLfloat y);
2184a49301eSmrg
2194a49301eSmrgvoid GLAPIENTRY
2203464ebd5Sriastradh_es_VertexAttrib2fv(GLuint indx, const GLfloat* values);
2214a49301eSmrg
2224a49301eSmrgvoid GLAPIENTRY
2233464ebd5Sriastradh_es_VertexAttrib3f(GLuint indx, GLfloat x, GLfloat y, GLfloat z);
2244a49301eSmrg
2254a49301eSmrgvoid GLAPIENTRY
2263464ebd5Sriastradh_es_VertexAttrib3fv(GLuint indx, const GLfloat* values);
2274a49301eSmrg
2284a49301eSmrgvoid GLAPIENTRY
2293464ebd5Sriastradh_es_VertexAttrib4fv(GLuint indx, const GLfloat* values);
2304a49301eSmrg
2317117f1b4Smrg#endif
232