Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenvbo_exec_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 * Authors: 00025 * Keith Whitwell <keith@tungstengraphics.com> 00026 */ 00027 00028 #include "main/glheader.h" 00029 #include "main/bufferobj.h" 00030 #include "main/context.h" 00031 #include "main/enums.h" 00032 #include "main/state.h" 00033 #include "main/macros.h" 00034 00035 #include "vbo_context.h" 00036 00037 00038 static void vbo_exec_debug_verts( struct vbo_exec_context *exec ) 00039 { 00040 GLuint count = exec->vtx.vert_count; 00041 GLuint i; 00042 00043 _mesa_printf("%s: %u vertices %d primitives, %d vertsize\n", 00044 __FUNCTION__, 00045 count, 00046 exec->vtx.prim_count, 00047 exec->vtx.vertex_size); 00048 00049 for (i = 0 ; i < exec->vtx.prim_count ; i++) { 00050 struct _mesa_prim *prim = &exec->vtx.prim[i]; 00051 _mesa_printf(" prim %d: %s%s %d..%d %s %s\n", 00052 i, 00053 _mesa_lookup_enum_by_nr(prim->mode), 00054 prim->weak ? " (weak)" : "", 00055 prim->start, 00056 prim->start + prim->count, 00057 prim->begin ? "BEGIN" : "(wrap)", 00058 prim->end ? "END" : "(wrap)"); 00059 } 00060 } 00061 00062 00063 /* 00064 * NOTE: Need to have calculated primitives by this point -- do it on the fly. 00065 * NOTE: Old 'parity' issue is gone. 00066 */ 00067 static GLuint vbo_copy_vertices( struct vbo_exec_context *exec ) 00068 { 00069 GLuint nr = exec->vtx.prim[exec->vtx.prim_count-1].count; 00070 GLuint ovf, i; 00071 GLuint sz = exec->vtx.vertex_size; 00072 GLfloat *dst = exec->vtx.copied.buffer; 00073 GLfloat *src = ((GLfloat *)exec->vtx.buffer_map + 00074 exec->vtx.prim[exec->vtx.prim_count-1].start * 00075 exec->vtx.vertex_size); 00076 00077 00078 switch( exec->ctx->Driver.CurrentExecPrimitive ) 00079 { 00080 case GL_POINTS: 00081 return 0; 00082 case GL_LINES: 00083 ovf = nr&1; 00084 for (i = 0 ; i < ovf ; i++) 00085 _mesa_memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz * sizeof(GLfloat) ); 00086 return i; 00087 case GL_TRIANGLES: 00088 ovf = nr%3; 00089 for (i = 0 ; i < ovf ; i++) 00090 _mesa_memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz * sizeof(GLfloat) ); 00091 return i; 00092 case GL_QUADS: 00093 ovf = nr&3; 00094 for (i = 0 ; i < ovf ; i++) 00095 _mesa_memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz * sizeof(GLfloat) ); 00096 return i; 00097 case GL_LINE_STRIP: 00098 if (nr == 0) 00099 return 0; 00100 else { 00101 _mesa_memcpy( dst, src+(nr-1)*sz, sz * sizeof(GLfloat) ); 00102 return 1; 00103 } 00104 case GL_LINE_LOOP: 00105 case GL_TRIANGLE_FAN: 00106 case GL_POLYGON: 00107 if (nr == 0) 00108 return 0; 00109 else if (nr == 1) { 00110 _mesa_memcpy( dst, src+0, sz * sizeof(GLfloat) ); 00111 return 1; 00112 } else { 00113 _mesa_memcpy( dst, src+0, sz * sizeof(GLfloat) ); 00114 _mesa_memcpy( dst+sz, src+(nr-1)*sz, sz * sizeof(GLfloat) ); 00115 return 2; 00116 } 00117 case GL_TRIANGLE_STRIP: 00118 /* no parity issue, but need to make sure the tri is not drawn twice */ 00119 if (nr & 1) { 00120 exec->vtx.prim[exec->vtx.prim_count-1].count--; 00121 } 00122 /* fallthrough */ 00123 case GL_QUAD_STRIP: 00124 switch (nr) { 00125 case 0: ovf = 0; break; 00126 case 1: ovf = 1; break; 00127 default: ovf = 2 + (nr&1); break; 00128 } 00129 for (i = 0 ; i < ovf ; i++) 00130 _mesa_memcpy( dst+i*sz, src+(nr-ovf+i)*sz, sz * sizeof(GLfloat) ); 00131 return i; 00132 case PRIM_OUTSIDE_BEGIN_END: 00133 return 0; 00134 default: 00135 assert(0); 00136 return 0; 00137 } 00138 } 00139 00140 00141 00142 /* TODO: populate these as the vertex is defined: 00143 */ 00144 static void vbo_exec_bind_arrays( GLcontext *ctx ) 00145 { 00146 struct vbo_context *vbo = vbo_context(ctx); 00147 struct vbo_exec_context *exec = &vbo->exec; 00148 struct gl_client_array *arrays = exec->vtx.arrays; 00149 GLuint count = exec->vtx.vert_count; 00150 GLubyte *data = exec->vtx.buffer_map; 00151 const GLuint *map; 00152 GLuint attr; 00153 00154 /* Install the default (ie Current) attributes first, then overlay 00155 * all active ones. 00156 */ 00157 switch (get_program_mode(exec->ctx)) { 00158 case VP_NONE: 00159 for (attr = 0; attr < 16; attr++) { 00160 exec->vtx.inputs[attr] = &vbo->legacy_currval[attr]; 00161 } 00162 for (attr = 0; attr < MAT_ATTRIB_MAX; attr++) { 00163 exec->vtx.inputs[attr + 16] = &vbo->mat_currval[attr]; 00164 } 00165 map = vbo->map_vp_none; 00166 break; 00167 case VP_NV: 00168 case VP_ARB: 00169 /* The aliasing of attributes for NV vertex programs has already 00170 * occurred. NV vertex programs cannot access material values, 00171 * nor attributes greater than VERT_ATTRIB_TEX7. 00172 */ 00173 for (attr = 0; attr < 16; attr++) { 00174 exec->vtx.inputs[attr] = &vbo->legacy_currval[attr]; 00175 exec->vtx.inputs[attr + 16] = &vbo->generic_currval[attr]; 00176 } 00177 map = vbo->map_vp_arb; 00178 00179 /* check if VERT_ATTRIB_POS is not read but VERT_BIT_GENERIC0 is read. 00180 * In that case we effectively need to route the data from 00181 * glVertexAttrib(0, val) calls to feed into the GENERIC0 input. 00182 */ 00183 if ((ctx->VertexProgram._Current->Base.InputsRead & VERT_BIT_POS) == 0 && 00184 (ctx->VertexProgram._Current->Base.InputsRead & VERT_BIT_GENERIC0)) { 00185 exec->vtx.inputs[16] = exec->vtx.inputs[0]; 00186 exec->vtx.attrsz[16] = exec->vtx.attrsz[0]; 00187 exec->vtx.attrsz[0] = 0; 00188 } 00189 break; 00190 default: 00191 assert(0); 00192 } 00193 00194 /* Make all active attributes (including edgeflag) available as 00195 * arrays of floats. 00196 */ 00197 for (attr = 0; attr < VERT_ATTRIB_MAX ; attr++) { 00198 const GLuint src = map[attr]; 00199 00200 if (exec->vtx.attrsz[src]) { 00201 /* override the default array set above */ 00202 exec->vtx.inputs[attr] = &arrays[attr]; 00203 00204 if (exec->vtx.bufferobj->Name) { 00205 /* a real buffer obj: Ptr is an offset, not a pointer*/ 00206 int offset; 00207 assert(exec->vtx.bufferobj->Pointer); /* buf should be mapped */ 00208 offset = (GLbyte *) data - (GLbyte *) exec->vtx.bufferobj->Pointer; 00209 assert(offset >= 0); 00210 arrays[attr].Ptr = (void *) offset; 00211 } 00212 else { 00213 /* Ptr into ordinary app memory */ 00214 arrays[attr].Ptr = (void *) data; 00215 } 00216 arrays[attr].Size = exec->vtx.attrsz[src]; 00217 arrays[attr].StrideB = exec->vtx.vertex_size * sizeof(GLfloat); 00218 arrays[attr].Stride = exec->vtx.vertex_size * sizeof(GLfloat); 00219 arrays[attr].Type = GL_FLOAT; 00220 arrays[attr].Enabled = 1; 00221 _mesa_reference_buffer_object(ctx, 00222 &arrays[attr].BufferObj, 00223 exec->vtx.bufferobj); 00224 arrays[attr]._MaxElement = count; /* ??? */ 00225 00226 data += exec->vtx.attrsz[src] * sizeof(GLfloat); 00227 } 00228 } 00229 } 00230 00231 00235 void vbo_exec_vtx_flush( struct vbo_exec_context *exec ) 00236 { 00237 if (0) 00238 vbo_exec_debug_verts( exec ); 00239 00240 00241 if (exec->vtx.prim_count && 00242 exec->vtx.vert_count) { 00243 00244 exec->vtx.copied.nr = vbo_copy_vertices( exec ); 00245 00246 if (exec->vtx.copied.nr != exec->vtx.vert_count) { 00247 GLcontext *ctx = exec->ctx; 00248 00249 GLenum target = GL_ARRAY_BUFFER_ARB; 00250 GLenum access = GL_READ_WRITE_ARB; 00251 GLenum usage = GL_STREAM_DRAW_ARB; 00252 GLsizei size = VBO_VERT_BUFFER_SIZE * sizeof(GLfloat); 00253 00254 /* Before the unmap (why?) 00255 */ 00256 vbo_exec_bind_arrays( ctx ); 00257 00258 /* if using a real VBO, unmap it before drawing */ 00259 if (exec->vtx.bufferobj->Name) { 00260 ctx->Driver.UnmapBuffer(ctx, target, exec->vtx.bufferobj); 00261 exec->vtx.buffer_map = NULL; 00262 } 00263 00264 vbo_context(ctx)->draw_prims( ctx, 00265 exec->vtx.inputs, 00266 exec->vtx.prim, 00267 exec->vtx.prim_count, 00268 NULL, 00269 0, 00270 exec->vtx.vert_count - 1); 00271 00272 /* If using a real VBO, get new storage */ 00273 if (exec->vtx.bufferobj->Name) { 00274 ctx->Driver.BufferData(ctx, target, size, NULL, usage, exec->vtx.bufferobj); 00275 exec->vtx.buffer_map = 00276 ctx->Driver.MapBuffer(ctx, target, access, exec->vtx.bufferobj); 00277 } 00278 } 00279 } 00280 00281 exec->vtx.prim_count = 0; 00282 exec->vtx.vert_count = 0; 00283 exec->vtx.vbptr = (GLfloat *)exec->vtx.buffer_map; 00284 } Generated on Fri May 25 2012 04:18:57 for ReactOS by
1.7.6.1
|