1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * mesa 3-D graphics library
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
5bf215546Sopenharmony_ci *
6bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
7bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
8bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
9bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
11bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
12bf215546Sopenharmony_ci *
13bf215546Sopenharmony_ci * The above copyright notice and this permission notice shall be included
14bf215546Sopenharmony_ci * in all copies or substantial portions of the Software.
15bf215546Sopenharmony_ci *
16bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20bf215546Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21bf215546Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22bf215546Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE.
23bf215546Sopenharmony_ci */
24bf215546Sopenharmony_ci
25bf215546Sopenharmony_ci/**
26bf215546Sopenharmony_ci * \brief Public interface to the VBO module
27bf215546Sopenharmony_ci * \author Keith Whitwell
28bf215546Sopenharmony_ci */
29bf215546Sopenharmony_ci
30bf215546Sopenharmony_ci
31bf215546Sopenharmony_ci#ifndef _VBO_H
32bf215546Sopenharmony_ci#define _VBO_H
33bf215546Sopenharmony_ci
34bf215546Sopenharmony_ci#include <stdbool.h>
35bf215546Sopenharmony_ci#include "main/glheader.h"
36bf215546Sopenharmony_ci#include "main/dd.h"
37bf215546Sopenharmony_ci#include "main/draw.h"
38bf215546Sopenharmony_ci#include "main/macros.h"
39bf215546Sopenharmony_ci#include "vbo_attrib.h"
40bf215546Sopenharmony_ci#include "gallium/include/pipe/p_state.h"
41bf215546Sopenharmony_ci
42bf215546Sopenharmony_ci#ifdef __cplusplus
43bf215546Sopenharmony_ciextern "C" {
44bf215546Sopenharmony_ci#endif
45bf215546Sopenharmony_ci
46bf215546Sopenharmony_cistruct gl_context;
47bf215546Sopenharmony_cistruct pipe_draw_info;
48bf215546Sopenharmony_cistruct pipe_draw_start_count_bias;
49bf215546Sopenharmony_ci
50bf215546Sopenharmony_ci/**
51bf215546Sopenharmony_ci * Max number of primitives (number of glBegin/End pairs) per VBO.
52bf215546Sopenharmony_ci */
53bf215546Sopenharmony_ci#define VBO_MAX_PRIM 64
54bf215546Sopenharmony_ci
55bf215546Sopenharmony_ci
56bf215546Sopenharmony_ci/**
57bf215546Sopenharmony_ci * Current vertex processing mode: fixed function vs. shader.
58bf215546Sopenharmony_ci * In reality, fixed function is probably implemented by a shader but that's
59bf215546Sopenharmony_ci * not what we care about here.
60bf215546Sopenharmony_ci */
61bf215546Sopenharmony_citypedef enum
62bf215546Sopenharmony_ci{
63bf215546Sopenharmony_ci   VP_MODE_FF,     /**< legacy / fixed function */
64bf215546Sopenharmony_ci   VP_MODE_SHADER, /**< ARB vertex program or GLSL vertex shader */
65bf215546Sopenharmony_ci   VP_MODE_MAX     /**< for sizing arrays */
66bf215546Sopenharmony_ci} gl_vertex_processing_mode;
67bf215546Sopenharmony_ci
68bf215546Sopenharmony_ci
69bf215546Sopenharmony_cistruct vbo_exec_eval1_map {
70bf215546Sopenharmony_ci   struct gl_1d_map *map;
71bf215546Sopenharmony_ci   GLuint sz;
72bf215546Sopenharmony_ci};
73bf215546Sopenharmony_ci
74bf215546Sopenharmony_cistruct vbo_exec_eval2_map {
75bf215546Sopenharmony_ci   struct gl_2d_map *map;
76bf215546Sopenharmony_ci   GLuint sz;
77bf215546Sopenharmony_ci};
78bf215546Sopenharmony_ci
79bf215546Sopenharmony_cistruct vbo_exec_copied_vtx {
80bf215546Sopenharmony_ci   fi_type buffer[VBO_ATTRIB_MAX * 4 * VBO_MAX_COPIED_VERTS];
81bf215546Sopenharmony_ci   GLuint nr;
82bf215546Sopenharmony_ci};
83bf215546Sopenharmony_ci
84bf215546Sopenharmony_cistruct vbo_markers
85bf215546Sopenharmony_ci{
86bf215546Sopenharmony_ci   /**
87bf215546Sopenharmony_ci    * If false and the primitive is a line loop, the first vertex is
88bf215546Sopenharmony_ci    * the beginning of the line loop and it won't be drawn.
89bf215546Sopenharmony_ci    * Instead, it will be moved to the end.
90bf215546Sopenharmony_ci    *
91bf215546Sopenharmony_ci    * Drivers shouldn't reset the line stipple pattern walker if begin is
92bf215546Sopenharmony_ci    * false and mode is a line strip.
93bf215546Sopenharmony_ci    */
94bf215546Sopenharmony_ci   bool begin;
95bf215546Sopenharmony_ci
96bf215546Sopenharmony_ci   /**
97bf215546Sopenharmony_ci    * If true and the primitive is a line loop, it will be closed.
98bf215546Sopenharmony_ci    */
99bf215546Sopenharmony_ci   bool end;
100bf215546Sopenharmony_ci};
101bf215546Sopenharmony_ci
102bf215546Sopenharmony_cistruct vbo_exec_context
103bf215546Sopenharmony_ci{
104bf215546Sopenharmony_ci   struct {
105bf215546Sopenharmony_ci      /* Multi draw where the mode can vary between draws. */
106bf215546Sopenharmony_ci      struct pipe_draw_info info;
107bf215546Sopenharmony_ci      struct pipe_draw_start_count_bias draw[VBO_MAX_PRIM];
108bf215546Sopenharmony_ci      GLubyte mode[VBO_MAX_PRIM];            /**< primitive modes per draw */
109bf215546Sopenharmony_ci      struct vbo_markers markers[VBO_MAX_PRIM];
110bf215546Sopenharmony_ci      unsigned prim_count;
111bf215546Sopenharmony_ci
112bf215546Sopenharmony_ci      struct gl_buffer_object *bufferobj;
113bf215546Sopenharmony_ci
114bf215546Sopenharmony_ci      GLuint vertex_size;       /* in dwords */
115bf215546Sopenharmony_ci      GLuint vertex_size_no_pos;
116bf215546Sopenharmony_ci
117bf215546Sopenharmony_ci      fi_type *buffer_map;
118bf215546Sopenharmony_ci      fi_type *buffer_ptr;              /* cursor, points into buffer */
119bf215546Sopenharmony_ci      GLuint   buffer_used;             /* in bytes */
120bf215546Sopenharmony_ci      unsigned buffer_offset;           /* only for persistent mappings */
121bf215546Sopenharmony_ci      fi_type vertex[VBO_ATTRIB_MAX*4]; /* current vertex */
122bf215546Sopenharmony_ci
123bf215546Sopenharmony_ci      GLuint vert_count;   /**< Number of vertices currently in buffer */
124bf215546Sopenharmony_ci      GLuint max_vert;     /**< Max number of vertices allowed in buffer */
125bf215546Sopenharmony_ci      struct vbo_exec_copied_vtx copied;
126bf215546Sopenharmony_ci
127bf215546Sopenharmony_ci      GLbitfield64 enabled;             /**< mask of enabled vbo arrays. */
128bf215546Sopenharmony_ci
129bf215546Sopenharmony_ci      /* Keep these packed in a structure for faster access. */
130bf215546Sopenharmony_ci      struct {
131bf215546Sopenharmony_ci         GLenum16 type;       /**< GL_FLOAT, GL_DOUBLE, GL_INT, etc */
132bf215546Sopenharmony_ci         GLubyte active_size; /**< number of components, but can shrink */
133bf215546Sopenharmony_ci         GLubyte size;        /**< number of components (1..4) */
134bf215546Sopenharmony_ci      } attr[VBO_ATTRIB_MAX];
135bf215546Sopenharmony_ci
136bf215546Sopenharmony_ci      /** pointers into the current 'vertex' array, declared above */
137bf215546Sopenharmony_ci      fi_type *attrptr[VBO_ATTRIB_MAX];
138bf215546Sopenharmony_ci   } vtx;
139bf215546Sopenharmony_ci
140bf215546Sopenharmony_ci   struct {
141bf215546Sopenharmony_ci      GLboolean recalculate_maps;
142bf215546Sopenharmony_ci      struct vbo_exec_eval1_map map1[VERT_ATTRIB_MAX];
143bf215546Sopenharmony_ci      struct vbo_exec_eval2_map map2[VERT_ATTRIB_MAX];
144bf215546Sopenharmony_ci   } eval;
145bf215546Sopenharmony_ci
146bf215546Sopenharmony_ci#ifndef NDEBUG
147bf215546Sopenharmony_ci   GLint flush_call_depth;
148bf215546Sopenharmony_ci#endif
149bf215546Sopenharmony_ci};
150bf215546Sopenharmony_ci
151bf215546Sopenharmony_ci
152bf215546Sopenharmony_cistruct vbo_save_context {
153bf215546Sopenharmony_ci   GLbitfield64 enabled; /**< mask of enabled vbo arrays. */
154bf215546Sopenharmony_ci   GLubyte attrsz[VBO_ATTRIB_MAX];  /**< 1, 2, 3 or 4 */
155bf215546Sopenharmony_ci   GLenum16 attrtype[VBO_ATTRIB_MAX];  /**< GL_FLOAT, GL_INT, etc */
156bf215546Sopenharmony_ci   GLubyte active_sz[VBO_ATTRIB_MAX];  /**< 1, 2, 3 or 4 */
157bf215546Sopenharmony_ci   GLuint vertex_size;  /**< size in GLfloats */
158bf215546Sopenharmony_ci   struct gl_vertex_array_object *VAO[VP_MODE_MAX];
159bf215546Sopenharmony_ci
160bf215546Sopenharmony_ci   struct vbo_save_vertex_store *vertex_store;
161bf215546Sopenharmony_ci   struct vbo_save_primitive_store *prim_store;
162bf215546Sopenharmony_ci   struct gl_buffer_object *current_bo;
163bf215546Sopenharmony_ci   unsigned current_bo_bytes_used;
164bf215546Sopenharmony_ci
165bf215546Sopenharmony_ci   fi_type vertex[VBO_ATTRIB_MAX*4];	   /* current values */
166bf215546Sopenharmony_ci   fi_type *attrptr[VBO_ATTRIB_MAX];
167bf215546Sopenharmony_ci
168bf215546Sopenharmony_ci   struct {
169bf215546Sopenharmony_ci      fi_type *buffer;
170bf215546Sopenharmony_ci      GLuint nr;
171bf215546Sopenharmony_ci   } copied;
172bf215546Sopenharmony_ci
173bf215546Sopenharmony_ci   fi_type *current[VBO_ATTRIB_MAX]; /* points into ctx->ListState */
174bf215546Sopenharmony_ci   GLubyte *currentsz[VBO_ATTRIB_MAX];
175bf215546Sopenharmony_ci
176bf215546Sopenharmony_ci   GLboolean dangling_attr_ref;
177bf215546Sopenharmony_ci   GLboolean out_of_memory;  /**< True if last VBO allocation failed */
178bf215546Sopenharmony_ci   bool no_current_update;
179bf215546Sopenharmony_ci};
180bf215546Sopenharmony_ci
181bf215546Sopenharmony_ciGLboolean
182bf215546Sopenharmony_ci_mesa_using_noop_vtxfmt(const struct _glapi_table *dispatch);
183bf215546Sopenharmony_ci
184bf215546Sopenharmony_ciGLboolean
185bf215546Sopenharmony_ci_vbo_CreateContext(struct gl_context *ctx);
186bf215546Sopenharmony_ci
187bf215546Sopenharmony_civoid
188bf215546Sopenharmony_ci_vbo_DestroyContext(struct gl_context *ctx);
189bf215546Sopenharmony_ci
190bf215546Sopenharmony_civoid
191bf215546Sopenharmony_civbo_install_exec_vtxfmt(struct gl_context *ctx);
192bf215546Sopenharmony_ci
193bf215546Sopenharmony_civoid
194bf215546Sopenharmony_civbo_install_hw_select_begin_end(struct gl_context *ctx);
195bf215546Sopenharmony_ci
196bf215546Sopenharmony_civoid
197bf215546Sopenharmony_civbo_install_exec_vtxfmt_noop(struct gl_context *ctx);
198bf215546Sopenharmony_ci
199bf215546Sopenharmony_civoid
200bf215546Sopenharmony_civbo_install_save_vtxfmt_noop(struct gl_context *ctx);
201bf215546Sopenharmony_ci
202bf215546Sopenharmony_civoid
203bf215546Sopenharmony_civbo_exec_update_eval_maps(struct gl_context *ctx);
204bf215546Sopenharmony_ci
205bf215546Sopenharmony_civoid
206bf215546Sopenharmony_civbo_exec_FlushVertices(struct gl_context *ctx, GLuint flags);
207bf215546Sopenharmony_ci
208bf215546Sopenharmony_civoid
209bf215546Sopenharmony_civbo_save_SaveFlushVertices(struct gl_context *ctx);
210bf215546Sopenharmony_ci
211bf215546Sopenharmony_civoid
212bf215546Sopenharmony_civbo_save_NotifyBegin(struct gl_context *ctx, GLenum mode,
213bf215546Sopenharmony_ci                     bool no_current_update);
214bf215546Sopenharmony_ci
215bf215546Sopenharmony_civoid
216bf215546Sopenharmony_civbo_save_NewList(struct gl_context *ctx, GLuint list, GLenum mode);
217bf215546Sopenharmony_ci
218bf215546Sopenharmony_civoid
219bf215546Sopenharmony_civbo_save_EndList(struct gl_context *ctx);
220bf215546Sopenharmony_ci
221bf215546Sopenharmony_civoid
222bf215546Sopenharmony_civbo_delete_minmax_cache(struct gl_buffer_object *bufferObj);
223bf215546Sopenharmony_ci
224bf215546Sopenharmony_civoid
225bf215546Sopenharmony_civbo_get_minmax_index_mapped(unsigned count, unsigned index_size,
226bf215546Sopenharmony_ci                            unsigned restartIndex, bool restart,
227bf215546Sopenharmony_ci                            const void *indices,
228bf215546Sopenharmony_ci                            unsigned *min_index, unsigned *max_index);
229bf215546Sopenharmony_ci
230bf215546Sopenharmony_civoid
231bf215546Sopenharmony_civbo_get_minmax_indices(struct gl_context *ctx, const struct _mesa_prim *prim,
232bf215546Sopenharmony_ci                       const struct _mesa_index_buffer *ib,
233bf215546Sopenharmony_ci                       GLuint *min_index, GLuint *max_index, GLuint nr_prims,
234bf215546Sopenharmony_ci                       bool primitive_restart,
235bf215546Sopenharmony_ci                       unsigned restart_index);
236bf215546Sopenharmony_ci
237bf215546Sopenharmony_cibool
238bf215546Sopenharmony_civbo_get_minmax_indices_gallium(struct gl_context *ctx,
239bf215546Sopenharmony_ci                               struct pipe_draw_info *info,
240bf215546Sopenharmony_ci                               const struct pipe_draw_start_count_bias *draws,
241bf215546Sopenharmony_ci                               unsigned num_draws);
242bf215546Sopenharmony_ci
243bf215546Sopenharmony_ciconst struct gl_array_attributes*
244bf215546Sopenharmony_ci_vbo_current_attrib(const struct gl_context *ctx, gl_vert_attrib attr);
245bf215546Sopenharmony_ci
246bf215546Sopenharmony_civoid GLAPIENTRY
247bf215546Sopenharmony_ci_es_Color4f(GLfloat r, GLfloat g, GLfloat b, GLfloat a);
248bf215546Sopenharmony_ci
249bf215546Sopenharmony_civoid GLAPIENTRY
250bf215546Sopenharmony_ci_es_Normal3f(GLfloat x, GLfloat y, GLfloat z);
251bf215546Sopenharmony_ci
252bf215546Sopenharmony_civoid GLAPIENTRY
253bf215546Sopenharmony_ci_es_MultiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q);
254bf215546Sopenharmony_ci
255bf215546Sopenharmony_civoid GLAPIENTRY
256bf215546Sopenharmony_ci_es_Materialfv(GLenum face, GLenum pname, const GLfloat *params);
257bf215546Sopenharmony_ci
258bf215546Sopenharmony_civoid GLAPIENTRY
259bf215546Sopenharmony_ci_es_Materialf(GLenum face, GLenum pname, GLfloat param);
260bf215546Sopenharmony_ci
261bf215546Sopenharmony_ci#ifdef __cplusplus
262bf215546Sopenharmony_ci} // extern "C"
263bf215546Sopenharmony_ci#endif
264bf215546Sopenharmony_ci
265bf215546Sopenharmony_ci#endif
266