Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4358 | Serge | 1 | /* |
2 | * mesa 3-D graphics library |
||
3 | * |
||
4 | * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. |
||
5 | * |
||
6 | * Permission is hereby granted, free of charge, to any person obtaining a |
||
7 | * copy of this software and associated documentation files (the "Software"), |
||
8 | * to deal in the Software without restriction, including without limitation |
||
9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||
10 | * and/or sell copies of the Software, and to permit persons to whom the |
||
11 | * Software is furnished to do so, subject to the following conditions: |
||
12 | * |
||
13 | * The above copyright notice and this permission notice shall be included |
||
14 | * in all copies or substantial portions of the Software. |
||
15 | * |
||
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
||
17 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||
19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
||
20 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
||
21 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
||
22 | * OTHER DEALINGS IN THE SOFTWARE. |
||
23 | */ |
||
24 | |||
25 | /** |
||
26 | * \file vbo_context.h |
||
27 | * \brief VBO builder module datatypes and definitions. |
||
28 | * \author Keith Whitwell |
||
29 | */ |
||
30 | |||
31 | |||
32 | /** |
||
33 | * \mainpage The VBO builder module |
||
34 | * |
||
35 | * This module hooks into the GL dispatch table and catches all vertex |
||
36 | * building and drawing commands, such as glVertex3f, glBegin and |
||
37 | * glDrawArrays. The module stores all incoming vertex data as arrays |
||
38 | * in GL vertex buffer objects (VBOs), and translates all drawing |
||
39 | * commands into calls to a driver supplied DrawPrimitives() callback. |
||
40 | * |
||
41 | * The module captures both immediate mode and display list drawing, |
||
42 | * and manages the allocation, reference counting and deallocation of |
||
43 | * vertex buffer objects itself. |
||
44 | * |
||
45 | * The DrawPrimitives() callback can be either implemented by the |
||
46 | * driver itself or hooked to the tnl module's _tnl_draw_primitives() |
||
47 | * function for hardware without tnl capablilties or during fallbacks. |
||
48 | */ |
||
49 | |||
50 | |||
51 | #ifndef _VBO_CONTEXT_H |
||
52 | #define _VBO_CONTEXT_H |
||
53 | |||
54 | #include "vbo.h" |
||
55 | #include "vbo_attrib.h" |
||
56 | #include "vbo_exec.h" |
||
57 | #include "vbo_save.h" |
||
58 | |||
59 | |||
60 | /** Used to signal when transitioning from one kind of drawing method |
||
61 | * to another. |
||
62 | */ |
||
63 | enum draw_method |
||
64 | { |
||
65 | DRAW_NONE, /**< Initial value only */ |
||
66 | DRAW_BEGIN_END, |
||
67 | DRAW_DISPLAY_LIST, |
||
68 | DRAW_ARRAYS |
||
69 | }; |
||
70 | |||
71 | |||
72 | struct vbo_context { |
||
73 | struct gl_client_array currval[VBO_ATTRIB_MAX]; |
||
74 | |||
75 | /** Map VERT_ATTRIB_x to VBO_ATTRIB_y */ |
||
76 | GLuint map_vp_none[VERT_ATTRIB_MAX]; |
||
77 | GLuint map_vp_arb[VERT_ATTRIB_MAX]; |
||
78 | |||
79 | struct vbo_exec_context exec; |
||
80 | struct vbo_save_context save; |
||
81 | |||
82 | /* Callback into the driver. This must always succeed, the driver |
||
83 | * is responsible for initiating any fallback actions required: |
||
84 | */ |
||
85 | vbo_draw_func draw_prims; |
||
86 | |||
87 | enum draw_method last_draw_method; |
||
88 | }; |
||
89 | |||
90 | |||
91 | static inline struct vbo_context *vbo_context(struct gl_context *ctx) |
||
92 | { |
||
93 | return (struct vbo_context *)(ctx->swtnl_im); |
||
94 | } |
||
95 | |||
96 | |||
97 | /** |
||
98 | * Return VP_x token to indicate whether we're running fixed-function |
||
99 | * vertex transformation, an NV vertex program or ARB vertex program/shader. |
||
100 | */ |
||
101 | static inline enum vp_mode |
||
102 | get_program_mode( struct gl_context *ctx ) |
||
103 | { |
||
104 | if (!ctx->VertexProgram._Current) |
||
105 | return VP_NONE; |
||
106 | else if (ctx->VertexProgram._Current == ctx->VertexProgram._TnlProgram) |
||
107 | return VP_NONE; |
||
108 | else |
||
109 | return VP_ARB; |
||
110 | } |
||
111 | |||
112 | |||
113 | /** |
||
114 | * This is called by glBegin, glDrawArrays and glDrawElements (and |
||
115 | * variations of those calls). When we transition from immediate mode |
||
116 | * drawing to array drawing we need to invalidate the array state. |
||
117 | * |
||
118 | * glBegin/End builds vertex arrays. Those arrays may look identical |
||
119 | * to glDrawArrays arrays except that the position of the elements may |
||
120 | * be different. For example, arrays of (position3v, normal3f) vs. arrays |
||
121 | * of (normal3f, position3f). So we need to make sure we notify drivers |
||
122 | * that arrays may be changing. |
||
123 | */ |
||
124 | static inline void |
||
125 | vbo_draw_method(struct vbo_context *vbo, enum draw_method method) |
||
126 | { |
||
127 | if (vbo->last_draw_method != method) { |
||
128 | struct gl_context *ctx = vbo->exec.ctx; |
||
129 | |||
130 | switch (method) { |
||
131 | case DRAW_ARRAYS: |
||
132 | ctx->Array._DrawArrays = vbo->exec.array.inputs; |
||
133 | break; |
||
134 | case DRAW_BEGIN_END: |
||
135 | ctx->Array._DrawArrays = vbo->exec.vtx.inputs; |
||
136 | break; |
||
137 | case DRAW_DISPLAY_LIST: |
||
138 | ctx->Array._DrawArrays = vbo->save.inputs; |
||
139 | break; |
||
140 | default: |
||
141 | ASSERT(0); |
||
142 | } |
||
143 | |||
144 | ctx->NewDriverState |= ctx->DriverFlags.NewArray; |
||
145 | vbo->last_draw_method = method; |
||
146 | } |
||
147 | } |
||
148 | |||
149 | /** |
||
150 | * Return if format is integer. The immediate mode commands only emit floats |
||
151 | * for non-integer types, thus everything else is integer. |
||
152 | */ |
||
153 | static inline GLboolean |
||
154 | vbo_attrtype_to_integer_flag(GLenum format) |
||
155 | { |
||
156 | switch (format) { |
||
157 | case GL_FLOAT: |
||
158 | return GL_FALSE; |
||
159 | case GL_INT: |
||
160 | case GL_UNSIGNED_INT: |
||
161 | return GL_TRUE; |
||
162 | default: |
||
163 | ASSERT(0); |
||
164 | return GL_FALSE; |
||
165 | } |
||
166 | } |
||
167 | |||
168 | |||
169 | /** |
||
170 | * Return default component values for the given format. |
||
171 | * The return type is an array of floats, because that's how we declare |
||
172 | * the vertex storage despite the fact we sometimes store integers in there. |
||
173 | */ |
||
174 | static inline const GLfloat * |
||
175 | vbo_get_default_vals_as_float(GLenum format) |
||
176 | { |
||
177 | static const GLfloat default_float[4] = { 0, 0, 0, 1 }; |
||
178 | static const GLint default_int[4] = { 0, 0, 0, 1 }; |
||
179 | |||
180 | switch (format) { |
||
181 | case GL_FLOAT: |
||
182 | return default_float; |
||
183 | case GL_INT: |
||
184 | case GL_UNSIGNED_INT: |
||
185 | return (const GLfloat*)default_int; |
||
186 | default: |
||
187 | ASSERT(0); |
||
188 | return NULL; |
||
189 | } |
||
190 | } |
||
191 | |||
192 | #endif> |