Revert "st/mesa: Always recalculate invalid index bounds."
[mesa.git] / src / mesa / vbo / vbo_exec.h
1 /**************************************************************************
2
3 Copyright 2002 Tungsten Graphics Inc., Cedar Park, Texas.
4
5 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 on the rights to use, copy, modify, merge, publish, distribute, sub
11 license, and/or sell copies of the Software, and to permit persons to whom
12 the Software is furnished to do so, subject to the following conditions:
13
14 The above copyright notice and this permission notice (including the next
15 paragraph) shall be included in all copies or substantial portions of the
16 Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 TUNGSTEN GRAPHICS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 USE OR OTHER DEALINGS IN THE SOFTWARE.
25
26 **************************************************************************/
27
28 /*
29 * Authors:
30 * Keith Whitwell <keith@tungstengraphics.com>
31 *
32 */
33
34 #ifndef __VBO_EXEC_H__
35 #define __VBO_EXEC_H__
36
37 #include "main/mtypes.h"
38 #include "vbo.h"
39 #include "vbo_attrib.h"
40
41
42 #define VBO_MAX_PRIM 64
43
44 /* Wierd implementation stuff:
45 */
46 #define VBO_VERT_BUFFER_SIZE (1024*64) /* bytes */
47 #define VBO_MAX_ATTR_CODEGEN 16
48 #define ERROR_ATTRIB 16
49
50
51 /** Current vertex program mode */
52 enum vp_mode {
53 VP_NONE, /**< fixed function */
54 VP_NV, /**< NV vertex program */
55 VP_ARB /**< ARB vertex program or GLSL vertex shader */
56 };
57
58
59 struct vbo_exec_eval1_map {
60 struct gl_1d_map *map;
61 GLuint sz;
62 };
63
64 struct vbo_exec_eval2_map {
65 struct gl_2d_map *map;
66 GLuint sz;
67 };
68
69
70
71 struct vbo_exec_copied_vtx {
72 GLfloat buffer[VBO_ATTRIB_MAX * 4 * VBO_MAX_COPIED_VERTS];
73 GLuint nr;
74 };
75
76
77 typedef void (*vbo_attrfv_func)( const GLfloat * );
78
79
80 struct vbo_exec_context
81 {
82 GLcontext *ctx;
83 GLvertexformat vtxfmt;
84
85 struct {
86 struct gl_buffer_object *bufferobj;
87
88 GLuint vertex_size; /* in dwords */
89
90 struct _mesa_prim prim[VBO_MAX_PRIM];
91 GLuint prim_count;
92
93 GLfloat *buffer_map;
94 GLfloat *buffer_ptr; /* cursor, points into buffer */
95 GLuint buffer_used; /* in bytes */
96 GLfloat vertex[VBO_ATTRIB_MAX*4]; /* current vertex */
97
98 GLuint vert_count;
99 GLuint max_vert;
100 struct vbo_exec_copied_vtx copied;
101
102 GLubyte attrsz[VBO_ATTRIB_MAX];
103 GLubyte active_sz[VBO_ATTRIB_MAX];
104
105 GLfloat *attrptr[VBO_ATTRIB_MAX];
106 struct gl_client_array arrays[VERT_ATTRIB_MAX];
107
108 /* According to program mode, the values above plus current
109 * values are squashed down to the 32 attributes passed to the
110 * vertex program below:
111 */
112 enum vp_mode program_mode;
113 GLuint enabled_flags;
114 const struct gl_client_array *inputs[VERT_ATTRIB_MAX];
115 } vtx;
116
117
118 struct {
119 GLboolean recalculate_maps;
120 struct vbo_exec_eval1_map map1[VERT_ATTRIB_MAX];
121 struct vbo_exec_eval2_map map2[VERT_ATTRIB_MAX];
122 } eval;
123
124 struct {
125 enum vp_mode program_mode;
126 GLuint enabled_flags;
127 GLuint array_obj;
128
129 /* These just mirror the current arrayobj (todo: make arrayobj
130 * look like this and remove the mirror):
131 */
132 const struct gl_client_array *legacy_array[16];
133 const struct gl_client_array *generic_array[16];
134
135 /* Arrays and current values manipulated according to program
136 * mode, etc. These are the attributes as seen by vertex
137 * programs:
138 */
139 const struct gl_client_array *inputs[VERT_ATTRIB_MAX];
140 } array;
141
142 #ifdef DEBUG
143 GLint flush_call_depth;
144 #endif
145 };
146
147
148
149 /* External API:
150 */
151 void vbo_exec_init( GLcontext *ctx );
152 void vbo_exec_destroy( GLcontext *ctx );
153 void vbo_exec_invalidate_state( GLcontext *ctx, GLuint new_state );
154 void vbo_exec_FlushVertices_internal( GLcontext *ctx, GLboolean unmap );
155
156 void vbo_exec_BeginVertices( GLcontext *ctx );
157 void vbo_exec_FlushVertices( GLcontext *ctx, GLuint flags );
158
159
160 /* Internal functions:
161 */
162 void vbo_exec_array_init( struct vbo_exec_context *exec );
163 void vbo_exec_array_destroy( struct vbo_exec_context *exec );
164
165
166 void vbo_exec_vtx_init( struct vbo_exec_context *exec );
167 void vbo_exec_vtx_destroy( struct vbo_exec_context *exec );
168
169 #if FEATURE_beginend
170
171 void vbo_exec_vtx_flush( struct vbo_exec_context *exec, GLboolean unmap );
172 void vbo_exec_vtx_map( struct vbo_exec_context *exec );
173
174 #else /* FEATURE_beginend */
175
176 static INLINE void
177 vbo_exec_vtx_flush( struct vbo_exec_context *exec, GLboolean unmap )
178 {
179 }
180
181 static INLINE void
182 vbo_exec_vtx_map( struct vbo_exec_context *exec )
183 {
184 }
185
186 #endif /* FEATURE_beginend */
187
188 void vbo_exec_vtx_wrap( struct vbo_exec_context *exec );
189
190 void vbo_exec_eval_update( struct vbo_exec_context *exec );
191
192 void vbo_exec_do_EvalCoord2f( struct vbo_exec_context *exec,
193 GLfloat u, GLfloat v );
194
195 void vbo_exec_do_EvalCoord1f( struct vbo_exec_context *exec,
196 GLfloat u);
197
198 extern GLboolean
199 vbo_validate_shaders(GLcontext *ctx);
200
201 #endif