Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenvbo_save_draw.c
Go to the documentation of this file.
00001 /* 00002 * Mesa 3-D graphics library 00003 * Version: 7.2 00004 * 00005 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. 00006 * 00007 * Permission is hereby granted, free of charge, to any person obtaining a 00008 * copy of this software and associated documentation files (the "Software"), 00009 * to deal in the Software without restriction, including without limitation 00010 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00011 * and/or sell copies of the Software, and to permit persons to whom the 00012 * Software is furnished to do so, subject to the following conditions: 00013 * 00014 * The above copyright notice and this permission notice shall be included 00015 * in all copies or substantial portions of the Software. 00016 * 00017 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00018 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00019 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 00020 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 00021 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 00022 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00023 */ 00024 00025 /* Author: 00026 * Keith Whitwell <keith@tungstengraphics.com> 00027 */ 00028 00029 #include "main/glheader.h" 00030 #include "main/bufferobj.h" 00031 #include "main/context.h" 00032 #include "main/imports.h" 00033 #include "main/mtypes.h" 00034 #include "main/macros.h" 00035 #include "main/light.h" 00036 #include "main/state.h" 00037 00038 #include "vbo_context.h" 00039 00040 00041 /* 00042 * After playback, copy everything but the position from the 00043 * last vertex to the saved state 00044 */ 00045 static void _playback_copy_to_current( GLcontext *ctx, 00046 const struct vbo_save_vertex_list *node ) 00047 { 00048 struct vbo_context *vbo = vbo_context(ctx); 00049 GLfloat vertex[VBO_ATTRIB_MAX * 4], *data = vertex; 00050 GLuint i, offset; 00051 00052 if (node->count) 00053 offset = (node->buffer_offset + 00054 (node->count-1) * node->vertex_size * sizeof(GLfloat)); 00055 else 00056 offset = node->buffer_offset; 00057 00058 ctx->Driver.GetBufferSubData( ctx, 0, offset, 00059 node->vertex_size * sizeof(GLfloat), 00060 data, node->vertex_store->bufferobj ); 00061 00062 data += node->attrsz[0]; /* skip vertex position */ 00063 00064 for (i = VBO_ATTRIB_POS+1 ; i < VBO_ATTRIB_MAX ; i++) { 00065 if (node->attrsz[i]) { 00066 GLfloat *current = (GLfloat *)vbo->currval[i].Ptr; 00067 00068 COPY_CLEAN_4V(current, 00069 node->attrsz[i], 00070 data); 00071 00072 vbo->currval[i].Size = node->attrsz[i]; 00073 00074 data += node->attrsz[i]; 00075 00076 if (i >= VBO_ATTRIB_FIRST_MATERIAL && 00077 i <= VBO_ATTRIB_LAST_MATERIAL) 00078 ctx->NewState |= _NEW_LIGHT; 00079 } 00080 } 00081 00082 /* Colormaterial -- this kindof sucks. 00083 */ 00084 if (ctx->Light.ColorMaterialEnabled) { 00085 _mesa_update_color_material(ctx, ctx->Current.Attrib[VBO_ATTRIB_COLOR0]); 00086 } 00087 00088 /* CurrentExecPrimitive 00089 */ 00090 if (node->prim_count) { 00091 const struct _mesa_prim *prim = &node->prim[node->prim_count - 1]; 00092 if (prim->end) 00093 ctx->Driver.CurrentExecPrimitive = PRIM_OUTSIDE_BEGIN_END; 00094 else 00095 ctx->Driver.CurrentExecPrimitive = prim->mode; 00096 } 00097 } 00098 00099 00100 00101 /* Treat the vertex storage as a VBO, define vertex arrays pointing 00102 * into it: 00103 */ 00104 static void vbo_bind_vertex_list( GLcontext *ctx, 00105 const struct vbo_save_vertex_list *node ) 00106 { 00107 struct vbo_context *vbo = vbo_context(ctx); 00108 struct vbo_save_context *save = &vbo->save; 00109 struct gl_client_array *arrays = save->arrays; 00110 GLuint data = node->buffer_offset; 00111 const GLuint *map; 00112 GLuint attr; 00113 GLubyte node_attrsz[VBO_ATTRIB_MAX]; /* copy of node->attrsz[] */ 00114 00115 memcpy(node_attrsz, node->attrsz, sizeof(node->attrsz)); 00116 00117 /* Install the default (ie Current) attributes first, then overlay 00118 * all active ones. 00119 */ 00120 switch (get_program_mode(ctx)) { 00121 case VP_NONE: 00122 for (attr = 0; attr < 16; attr++) { 00123 save->inputs[attr] = &vbo->legacy_currval[attr]; 00124 } 00125 for (attr = 0; attr < MAT_ATTRIB_MAX; attr++) { 00126 save->inputs[attr + 16] = &vbo->mat_currval[attr]; 00127 } 00128 map = vbo->map_vp_none; 00129 break; 00130 case VP_NV: 00131 case VP_ARB: 00132 /* The aliasing of attributes for NV vertex programs has already 00133 * occurred. NV vertex programs cannot access material values, 00134 * nor attributes greater than VERT_ATTRIB_TEX7. 00135 */ 00136 for (attr = 0; attr < 16; attr++) { 00137 save->inputs[attr] = &vbo->legacy_currval[attr]; 00138 save->inputs[attr + 16] = &vbo->generic_currval[attr]; 00139 } 00140 map = vbo->map_vp_arb; 00141 00142 /* check if VERT_ATTRIB_POS is not read but VERT_BIT_GENERIC0 is read. 00143 * In that case we effectively need to route the data from 00144 * glVertexAttrib(0, val) calls to feed into the GENERIC0 input. 00145 */ 00146 if ((ctx->VertexProgram._Current->Base.InputsRead & VERT_BIT_POS) == 0 && 00147 (ctx->VertexProgram._Current->Base.InputsRead & VERT_BIT_GENERIC0)) { 00148 save->inputs[16] = save->inputs[0]; 00149 node_attrsz[16] = node_attrsz[0]; 00150 node_attrsz[0] = 0; 00151 } 00152 break; 00153 default: 00154 assert(0); 00155 } 00156 00157 for (attr = 0; attr < VERT_ATTRIB_MAX; attr++) { 00158 GLuint src = map[attr]; 00159 00160 if (node_attrsz[src]) { 00161 /* override the default array set above */ 00162 save->inputs[attr] = &arrays[attr]; 00163 00164 arrays[attr].Ptr = (const GLubyte *) data; 00165 arrays[attr].Size = node->attrsz[src]; 00166 arrays[attr].StrideB = node->vertex_size * sizeof(GLfloat); 00167 arrays[attr].Stride = node->vertex_size * sizeof(GLfloat); 00168 arrays[attr].Type = GL_FLOAT; 00169 arrays[attr].Enabled = 1; 00170 _mesa_reference_buffer_object(ctx, 00171 &arrays[attr].BufferObj, 00172 node->vertex_store->bufferobj); 00173 arrays[attr]._MaxElement = node->count; /* ??? */ 00174 00175 assert(arrays[attr].BufferObj->Name); 00176 00177 data += node->attrsz[src] * sizeof(GLfloat); 00178 } 00179 } 00180 } 00181 00182 static void vbo_save_loopback_vertex_list( GLcontext *ctx, 00183 const struct vbo_save_vertex_list *list ) 00184 { 00185 const char *buffer = ctx->Driver.MapBuffer(ctx, 00186 GL_ARRAY_BUFFER_ARB, 00187 GL_READ_ONLY, /* ? */ 00188 list->vertex_store->bufferobj); 00189 00190 vbo_loopback_vertex_list( ctx, 00191 (const GLfloat *)(buffer + list->buffer_offset), 00192 list->attrsz, 00193 list->prim, 00194 list->prim_count, 00195 list->wrap_count, 00196 list->vertex_size); 00197 00198 ctx->Driver.UnmapBuffer(ctx, GL_ARRAY_BUFFER_ARB, 00199 list->vertex_store->bufferobj); 00200 } 00201 00202 00206 void vbo_save_playback_vertex_list( GLcontext *ctx, void *data ) 00207 { 00208 const struct vbo_save_vertex_list *node = (const struct vbo_save_vertex_list *) data; 00209 struct vbo_save_context *save = &vbo_context(ctx)->save; 00210 00211 FLUSH_CURRENT(ctx, 0); 00212 00213 if (node->prim_count > 0 && node->count > 0) { 00214 00215 if (ctx->Driver.CurrentExecPrimitive != PRIM_OUTSIDE_BEGIN_END && 00216 node->prim[0].begin) { 00217 00218 /* Degenerate case: list is called inside begin/end pair and 00219 * includes operations such as glBegin or glDrawArrays. 00220 */ 00221 if (0) 00222 _mesa_printf("displaylist recursive begin"); 00223 00224 vbo_save_loopback_vertex_list( ctx, node ); 00225 return; 00226 } 00227 else if (save->replay_flags) { 00228 /* Various degnerate cases: translate into immediate mode 00229 * calls rather than trying to execute in place. 00230 */ 00231 vbo_save_loopback_vertex_list( ctx, node ); 00232 return; 00233 } 00234 00235 if (ctx->NewState) 00236 _mesa_update_state( ctx ); 00237 00238 /* XXX also need to check if shader enabled, but invalid */ 00239 if ((ctx->VertexProgram.Enabled && !ctx->VertexProgram._Enabled) || 00240 (ctx->FragmentProgram.Enabled && !ctx->FragmentProgram._Enabled)) { 00241 _mesa_error(ctx, GL_INVALID_OPERATION, 00242 "glBegin (invalid vertex/fragment program)"); 00243 return; 00244 } 00245 00246 vbo_bind_vertex_list( ctx, node ); 00247 00248 vbo_context(ctx)->draw_prims( ctx, 00249 save->inputs, 00250 node->prim, 00251 node->prim_count, 00252 NULL, 00253 0, /* Node is a VBO, so this is ok */ 00254 node->count - 1); 00255 } 00256 00257 /* Copy to current? 00258 */ 00259 _playback_copy_to_current( ctx, node ); 00260 } Generated on Sat May 26 2012 04:19:38 for ReactOS by
1.7.6.1
|