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/** 2601e04c3fSmrg * \brief Public interface to the VBO module 277117f1b4Smrg * \author Keith Whitwell 287117f1b4Smrg */ 297117f1b4Smrg 307117f1b4Smrg 317117f1b4Smrg#ifndef _VBO_H 327117f1b4Smrg#define _VBO_H 337117f1b4Smrg 34af69d88dSmrg#include <stdbool.h> 353464ebd5Sriastradh#include "main/glheader.h" 367ec681f3Smrg#include "main/dd.h" 3701e04c3fSmrg#include "main/draw.h" 387ec681f3Smrg#include "main/macros.h" 397ec681f3Smrg#include "vbo_attrib.h" 407ec681f3Smrg#include "gallium/include/pipe/p_state.h" 4101e04c3fSmrg 4201e04c3fSmrg#ifdef __cplusplus 4301e04c3fSmrgextern "C" { 4401e04c3fSmrg#endif 453464ebd5Sriastradh 463464ebd5Sriastradhstruct gl_context; 477ec681f3Smrgstruct pipe_draw_info; 487ec681f3Smrgstruct pipe_draw_start_count_bias; 497ec681f3Smrg 507ec681f3Smrg/** 517ec681f3Smrg * Max number of primitives (number of glBegin/End pairs) per VBO. 527ec681f3Smrg */ 537ec681f3Smrg#define VBO_MAX_PRIM 64 547ec681f3Smrg 557ec681f3Smrg 567ec681f3Smrg/** 577ec681f3Smrg * Current vertex processing mode: fixed function vs. shader. 587ec681f3Smrg * In reality, fixed function is probably implemented by a shader but that's 597ec681f3Smrg * not what we care about here. 607ec681f3Smrg */ 617ec681f3Smrgtypedef enum 627ec681f3Smrg{ 637ec681f3Smrg VP_MODE_FF, /**< legacy / fixed function */ 647ec681f3Smrg VP_MODE_SHADER, /**< ARB vertex program or GLSL vertex shader */ 657ec681f3Smrg VP_MODE_MAX /**< for sizing arrays */ 667ec681f3Smrg} gl_vertex_processing_mode; 677ec681f3Smrg 687ec681f3Smrg 697ec681f3Smrgstruct vbo_exec_eval1_map { 707ec681f3Smrg struct gl_1d_map *map; 717ec681f3Smrg GLuint sz; 727ec681f3Smrg}; 737ec681f3Smrg 747ec681f3Smrgstruct vbo_exec_eval2_map { 757ec681f3Smrg struct gl_2d_map *map; 767ec681f3Smrg GLuint sz; 777ec681f3Smrg}; 787ec681f3Smrg 797ec681f3Smrgstruct vbo_exec_copied_vtx { 807ec681f3Smrg fi_type buffer[VBO_ATTRIB_MAX * 4 * VBO_MAX_COPIED_VERTS]; 817ec681f3Smrg GLuint nr; 827ec681f3Smrg}; 837ec681f3Smrg 847ec681f3Smrgstruct vbo_markers 857ec681f3Smrg{ 867ec681f3Smrg /** 877ec681f3Smrg * If false and the primitive is a line loop, the first vertex is 887ec681f3Smrg * the beginning of the line loop and it won't be drawn. 897ec681f3Smrg * Instead, it will be moved to the end. 907ec681f3Smrg * 917ec681f3Smrg * Drivers shouldn't reset the line stipple pattern walker if begin is 927ec681f3Smrg * false and mode is a line strip. 937ec681f3Smrg */ 947ec681f3Smrg bool begin; 957ec681f3Smrg 967ec681f3Smrg /** 977ec681f3Smrg * If true and the primitive is a line loop, it will be closed. 987ec681f3Smrg */ 997ec681f3Smrg bool end; 1007ec681f3Smrg}; 1017ec681f3Smrg 1027ec681f3Smrgstruct vbo_exec_context 1037ec681f3Smrg{ 1047ec681f3Smrg GLvertexformat vtxfmt; 1057ec681f3Smrg GLvertexformat vtxfmt_noop; 1067ec681f3Smrg 1077ec681f3Smrg struct { 1087ec681f3Smrg /* Multi draw where the mode can vary between draws. */ 1097ec681f3Smrg struct pipe_draw_info info; 1107ec681f3Smrg struct pipe_draw_start_count_bias draw[VBO_MAX_PRIM]; 1117ec681f3Smrg GLubyte mode[VBO_MAX_PRIM]; /**< primitive modes per draw */ 1127ec681f3Smrg struct vbo_markers markers[VBO_MAX_PRIM]; 1137ec681f3Smrg unsigned prim_count; 1147ec681f3Smrg 1157ec681f3Smrg struct gl_buffer_object *bufferobj; 1167ec681f3Smrg 1177ec681f3Smrg GLuint vertex_size; /* in dwords */ 1187ec681f3Smrg GLuint vertex_size_no_pos; 1197ec681f3Smrg 1207ec681f3Smrg fi_type *buffer_map; 1217ec681f3Smrg fi_type *buffer_ptr; /* cursor, points into buffer */ 1227ec681f3Smrg GLuint buffer_used; /* in bytes */ 1237ec681f3Smrg unsigned buffer_offset; /* only for persistent mappings */ 1247ec681f3Smrg fi_type vertex[VBO_ATTRIB_MAX*4]; /* current vertex */ 1257ec681f3Smrg 1267ec681f3Smrg GLuint vert_count; /**< Number of vertices currently in buffer */ 1277ec681f3Smrg GLuint max_vert; /**< Max number of vertices allowed in buffer */ 1287ec681f3Smrg struct vbo_exec_copied_vtx copied; 1297ec681f3Smrg 1307ec681f3Smrg GLbitfield64 enabled; /**< mask of enabled vbo arrays. */ 1317ec681f3Smrg 1327ec681f3Smrg /* Keep these packed in a structure for faster access. */ 1337ec681f3Smrg struct { 1347ec681f3Smrg GLenum16 type; /**< GL_FLOAT, GL_DOUBLE, GL_INT, etc */ 1357ec681f3Smrg GLubyte active_size; /**< number of components, but can shrink */ 1367ec681f3Smrg GLubyte size; /**< number of components (1..4) */ 1377ec681f3Smrg } attr[VBO_ATTRIB_MAX]; 1387ec681f3Smrg 1397ec681f3Smrg /** pointers into the current 'vertex' array, declared above */ 1407ec681f3Smrg fi_type *attrptr[VBO_ATTRIB_MAX]; 1417ec681f3Smrg } vtx; 1427ec681f3Smrg 1437ec681f3Smrg struct { 1447ec681f3Smrg GLboolean recalculate_maps; 1457ec681f3Smrg struct vbo_exec_eval1_map map1[VERT_ATTRIB_MAX]; 1467ec681f3Smrg struct vbo_exec_eval2_map map2[VERT_ATTRIB_MAX]; 1477ec681f3Smrg } eval; 1487ec681f3Smrg 1497ec681f3Smrg#ifndef NDEBUG 1507ec681f3Smrg GLint flush_call_depth; 1517ec681f3Smrg#endif 1527ec681f3Smrg}; 1537ec681f3Smrg 1547ec681f3Smrg 1557ec681f3Smrgstruct vbo_save_context { 1567ec681f3Smrg GLvertexformat vtxfmt; 1577ec681f3Smrg 1587ec681f3Smrg GLbitfield64 enabled; /**< mask of enabled vbo arrays. */ 1597ec681f3Smrg GLubyte attrsz[VBO_ATTRIB_MAX]; /**< 1, 2, 3 or 4 */ 1607ec681f3Smrg GLenum16 attrtype[VBO_ATTRIB_MAX]; /**< GL_FLOAT, GL_INT, etc */ 1617ec681f3Smrg GLubyte active_sz[VBO_ATTRIB_MAX]; /**< 1, 2, 3 or 4 */ 1627ec681f3Smrg GLuint vertex_size; /**< size in GLfloats */ 1637ec681f3Smrg struct gl_vertex_array_object *VAO[VP_MODE_MAX]; 1647ec681f3Smrg 1657ec681f3Smrg struct vbo_save_vertex_store *vertex_store; 1667ec681f3Smrg struct vbo_save_primitive_store *prim_store; 1677ec681f3Smrg struct gl_buffer_object *current_bo; 1687ec681f3Smrg unsigned current_bo_bytes_used; 1697ec681f3Smrg 1707ec681f3Smrg fi_type vertex[VBO_ATTRIB_MAX*4]; /* current values */ 1717ec681f3Smrg fi_type *attrptr[VBO_ATTRIB_MAX]; 1727ec681f3Smrg 1737ec681f3Smrg struct { 1747ec681f3Smrg fi_type *buffer; 1757ec681f3Smrg GLuint nr; 1767ec681f3Smrg } copied; 1777ec681f3Smrg 1787ec681f3Smrg fi_type *current[VBO_ATTRIB_MAX]; /* points into ctx->ListState */ 1797ec681f3Smrg GLubyte *currentsz[VBO_ATTRIB_MAX]; 1807ec681f3Smrg 1817ec681f3Smrg GLboolean dangling_attr_ref; 1827ec681f3Smrg GLboolean out_of_memory; /**< True if last VBO allocation failed */ 1837ec681f3Smrg bool no_current_update; 1847ec681f3Smrg}; 1857117f1b4Smrg 18601e04c3fSmrgGLboolean 1877ec681f3Smrg_vbo_CreateContext(struct gl_context *ctx, bool use_buffer_objects); 1887117f1b4Smrg 18901e04c3fSmrgvoid 19001e04c3fSmrg_vbo_DestroyContext(struct gl_context *ctx); 1917117f1b4Smrg 19201e04c3fSmrgvoid 1937ec681f3Smrgvbo_exec_update_eval_maps(struct gl_context *ctx); 1947117f1b4Smrg 19501e04c3fSmrgvoid 19601e04c3fSmrg_vbo_install_exec_vtxfmt(struct gl_context *ctx); 1977117f1b4Smrg 198af69d88dSmrgvoid 199af69d88dSmrgvbo_initialize_exec_dispatch(const struct gl_context *ctx, 200af69d88dSmrg struct _glapi_table *exec); 201af69d88dSmrg 202af69d88dSmrgvoid 203af69d88dSmrgvbo_initialize_save_dispatch(const struct gl_context *ctx, 204af69d88dSmrg struct _glapi_table *exec); 205af69d88dSmrg 20601e04c3fSmrgvoid 20701e04c3fSmrgvbo_exec_FlushVertices(struct gl_context *ctx, GLuint flags); 208af69d88dSmrg 20901e04c3fSmrgvoid 21001e04c3fSmrgvbo_save_SaveFlushVertices(struct gl_context *ctx); 2117117f1b4Smrg 21201e04c3fSmrgvoid 21301e04c3fSmrgvbo_save_NotifyBegin(struct gl_context *ctx, GLenum mode, 21401e04c3fSmrg bool no_current_update); 2157117f1b4Smrg 21601e04c3fSmrgvoid 21701e04c3fSmrgvbo_save_NewList(struct gl_context *ctx, GLuint list, GLenum mode); 2187117f1b4Smrg 21901e04c3fSmrgvoid 22001e04c3fSmrgvbo_save_EndList(struct gl_context *ctx); 2217117f1b4Smrg 22201e04c3fSmrgvoid 2237ec681f3Smrgvbo_delete_minmax_cache(struct gl_buffer_object *bufferObj); 2247117f1b4Smrg 22501e04c3fSmrgvoid 2267ec681f3Smrgvbo_get_minmax_index_mapped(unsigned count, unsigned index_size, 2277ec681f3Smrg unsigned restartIndex, bool restart, 2287ec681f3Smrg const void *indices, 2297ec681f3Smrg unsigned *min_index, unsigned *max_index); 230af69d88dSmrg 2314a49301eSmrgvoid 232af69d88dSmrgvbo_get_minmax_indices(struct gl_context *ctx, const struct _mesa_prim *prim, 233af69d88dSmrg const struct _mesa_index_buffer *ib, 2347ec681f3Smrg GLuint *min_index, GLuint *max_index, GLuint nr_prims, 2357ec681f3Smrg bool primitive_restart, 2367ec681f3Smrg unsigned restart_index); 2377ec681f3Smrg 2387ec681f3Smrgbool 2397ec681f3Smrgvbo_get_minmax_indices_gallium(struct gl_context *ctx, 2407ec681f3Smrg struct pipe_draw_info *info, 2417ec681f3Smrg const struct pipe_draw_start_count_bias *draws, 2427ec681f3Smrg unsigned num_draws); 24301e04c3fSmrg 24401e04c3fSmrgconst struct gl_array_attributes* 24501e04c3fSmrg_vbo_current_attrib(const struct gl_context *ctx, gl_vert_attrib attr); 24601e04c3fSmrg 24701e04c3fSmrg 24801e04c3fSmrgconst struct gl_vertex_buffer_binding* 24901e04c3fSmrg_vbo_current_binding(const struct gl_context *ctx); 25001e04c3fSmrg 25101e04c3fSmrg 2523464ebd5Sriastradhvoid GLAPIENTRY 2533464ebd5Sriastradh_es_Color4f(GLfloat r, GLfloat g, GLfloat b, GLfloat a); 2543464ebd5Sriastradh 2553464ebd5Sriastradhvoid GLAPIENTRY 2563464ebd5Sriastradh_es_Normal3f(GLfloat x, GLfloat y, GLfloat z); 2573464ebd5Sriastradh 2583464ebd5Sriastradhvoid GLAPIENTRY 2593464ebd5Sriastradh_es_MultiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q); 260c1f859d4Smrg 2613464ebd5Sriastradhvoid GLAPIENTRY 2623464ebd5Sriastradh_es_Materialfv(GLenum face, GLenum pname, const GLfloat *params); 263c1f859d4Smrg 2643464ebd5Sriastradhvoid GLAPIENTRY 2653464ebd5Sriastradh_es_Materialf(GLenum face, GLenum pname, GLfloat param); 2664a49301eSmrg 2673464ebd5Sriastradhvoid GLAPIENTRY 2683464ebd5Sriastradh_es_VertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); 2693464ebd5Sriastradh 2703464ebd5Sriastradhvoid GLAPIENTRY 2713464ebd5Sriastradh_es_VertexAttrib1f(GLuint indx, GLfloat x); 2723464ebd5Sriastradh 2733464ebd5Sriastradhvoid GLAPIENTRY 2743464ebd5Sriastradh_es_VertexAttrib1fv(GLuint indx, const GLfloat* values); 2754a49301eSmrg 2764a49301eSmrgvoid GLAPIENTRY 2773464ebd5Sriastradh_es_VertexAttrib2f(GLuint indx, GLfloat x, GLfloat y); 2784a49301eSmrg 2794a49301eSmrgvoid GLAPIENTRY 2803464ebd5Sriastradh_es_VertexAttrib2fv(GLuint indx, const GLfloat* values); 2814a49301eSmrg 2824a49301eSmrgvoid GLAPIENTRY 2833464ebd5Sriastradh_es_VertexAttrib3f(GLuint indx, GLfloat x, GLfloat y, GLfloat z); 2844a49301eSmrg 2854a49301eSmrgvoid GLAPIENTRY 2863464ebd5Sriastradh_es_VertexAttrib3fv(GLuint indx, const GLfloat* values); 2874a49301eSmrg 2884a49301eSmrgvoid GLAPIENTRY 2893464ebd5Sriastradh_es_VertexAttrib4fv(GLuint indx, const GLfloat* values); 2904a49301eSmrg 29101e04c3fSmrg#ifdef __cplusplus 29201e04c3fSmrg} // extern "C" 29301e04c3fSmrg#endif 29401e04c3fSmrg 2957117f1b4Smrg#endif 296