-Fix first frame -bug
[mesa.git] / src / mesa / drivers / dri / r300 / radeon_vtxfmt_a.c
1 #include "context.h"
2 #include "r300_context.h"
3 #include "r300_cmdbuf.h"
4 #include "radeon_mm.h"
5
6 #ifdef RADEON_VTXFMT_A
7
8 #define CONV(a, b) rmesa->state.VB.AttribPtr[(a)].size = ctx->Array.b.Size, \
9 rmesa->state.VB.AttribPtr[(a)].data = ctx->Array.b.BufferObj->Name ? \
10 ADD_POINTERS(ctx->Array.b.Ptr, ctx->Array.b.BufferObj->Data) : ctx->Array.b.Ptr, \
11 rmesa->state.VB.AttribPtr[(a)].stride = ctx->Array.b.StrideB, \
12 rmesa->state.VB.AttribPtr[(a)].type = ctx->Array.b.Type
13
14 static int setup_arrays(r300ContextPtr rmesa, GLint start)
15 {
16 int i;
17 struct dt def = { 4, GL_FLOAT, 0, NULL };
18 GLcontext *ctx;
19 GLuint enabled = 0;
20
21 ctx = rmesa->radeon.glCtx;
22
23 memset(rmesa->state.VB.AttribPtr, 0, VERT_ATTRIB_MAX*sizeof(struct dt));
24
25 CONV(VERT_ATTRIB_POS, Vertex);
26 if (ctx->Array.Vertex.Enabled)
27 enabled |= 1 << VERT_ATTRIB_POS;
28
29 CONV(VERT_ATTRIB_NORMAL, Normal);
30 if (ctx->Array.Normal.Enabled)
31 enabled |= 1 << VERT_ATTRIB_NORMAL;
32
33 CONV(VERT_ATTRIB_COLOR0, Color);
34 if (ctx->Array.Color.Enabled)
35 enabled |= 1 << VERT_ATTRIB_COLOR0;
36
37 CONV(VERT_ATTRIB_COLOR1, SecondaryColor);
38 if (ctx->Array.SecondaryColor.Enabled)
39 enabled |= 1 << VERT_ATTRIB_COLOR1;
40
41 CONV(VERT_ATTRIB_FOG, FogCoord);
42 if (ctx->Array.FogCoord.Enabled)
43 enabled |= 1 << VERT_ATTRIB_FOG;
44
45 for (i=0; i < MAX_TEXTURE_COORD_UNITS; i++) {
46 CONV(VERT_ATTRIB_TEX0 + i, TexCoord[i]);
47
48 if(ctx->Array.TexCoord[i].Enabled) {
49 enabled |= 1 << (VERT_ATTRIB_TEX0+i);
50 }
51
52 }
53
54 for (i=0; i < VERT_ATTRIB_MAX; i++) {
55 if (enabled & (1 << i)) {
56 rmesa->state.VB.AttribPtr[i].data += rmesa->state.VB.AttribPtr[i].stride * start;
57 } else {
58 def.data = ctx->Current.Attrib[i];
59 memcpy(&rmesa->state.VB.AttribPtr[i], &def, sizeof(struct dt));
60 }
61
62 /*if(rmesa->state.VB.AttribPtr[i].data == ctx->Current.Attrib[i])
63 fprintf(stderr, "%d is default coord\n", i);*/
64 }
65
66 for(i=0; i < VERT_ATTRIB_MAX; i++){
67 if(rmesa->state.VB.AttribPtr[i].type != GL_UNSIGNED_BYTE &&
68 rmesa->state.VB.AttribPtr[i].type != GL_FLOAT){
69 WARN_ONCE("Unsupported format %d at index %d\n", rmesa->state.VB.AttribPtr[i].type, i);
70 return -1;
71 }
72 if(rmesa->state.VB.AttribPtr[i].type == GL_UNSIGNED_BYTE &&
73 rmesa->state.VB.AttribPtr[i].size != 4){
74 WARN_ONCE("Unsupported component count for ub colors\n");
75 return -1;
76 }
77
78 /*fprintf(stderr, "%d: ", i);
79
80 switch(rmesa->state.VB.AttribPtr[i].type){
81 case GL_BYTE: fprintf(stderr, "byte "); break;
82 case GL_UNSIGNED_BYTE: fprintf(stderr, "u byte "); break;
83 case GL_SHORT: fprintf(stderr, "short "); break;
84 case GL_UNSIGNED_SHORT: fprintf(stderr, "u short "); break;
85 case GL_INT: fprintf(stderr, "int "); break;
86 case GL_UNSIGNED_INT: fprintf(stderr, "u int "); break;
87 case GL_FLOAT: fprintf(stderr, "float "); break;
88 case GL_2_BYTES: fprintf(stderr, "2 bytes "); break;
89 case GL_3_BYTES: fprintf(stderr, "3 bytes "); break;
90 case GL_4_BYTES: fprintf(stderr, "4 bytes "); break;
91 case GL_DOUBLE: fprintf(stderr, "double "); break;
92 default: fprintf(stderr, "unknown "); break;
93 }
94
95 fprintf(stderr, "Size %d ", rmesa->state.VB.AttribPtr[i].size);
96 fprintf(stderr, "Ptr %p ", rmesa->state.VB.AttribPtr[i].data);
97 fprintf(stderr, "Stride %d ", rmesa->state.VB.AttribPtr[i].stride);
98 fprintf(stderr, "\n");*/
99 }
100 return 0;
101 }
102
103 void radeonDrawElements( GLenum mode, GLsizei count, GLenum type, const GLvoid *indices )
104 {
105 GET_CURRENT_CONTEXT(ctx);
106 r300ContextPtr rmesa = R300_CONTEXT(ctx);
107 int elt_size;
108 int i;
109 unsigned int min = ~0, max = 0;
110 struct tnl_prim prim;
111 static void *ptr = NULL;
112 static struct r300_dma_region rvb;
113
114 if (ctx->Array.ElementArrayBufferObj->Name) {
115 /* use indices in the buffer object */
116 if (!ctx->Array.ElementArrayBufferObj->Data) {
117 _mesa_warning(ctx, "DrawRangeElements with empty vertex elements buffer!");
118 return;
119 }
120 /* actual address is the sum of pointers */
121 indices = (const GLvoid *)
122 ADD_POINTERS(ctx->Array.ElementArrayBufferObj->Data, (const GLubyte *) indices);
123 }
124
125 if (!_mesa_validate_DrawElements( ctx, mode, count, type, indices ))
126 return;
127
128 FLUSH_CURRENT( ctx, 0 );
129 /*
130 fprintf(stderr, "dt at %s:\n", __FUNCTION__);
131 for(i=0; i < VERT_ATTRIB_MAX; i++){
132 fprintf(stderr, "dt %d:", i);
133 dump_dt(&rmesa->state.VB.AttribPtr[i], rmesa->state.VB.Count);
134 }*/
135 r300ReleaseDmaRegion(rmesa, &rvb, __FUNCTION__);
136
137 switch (type) {
138 case GL_UNSIGNED_BYTE:
139 for (i=0; i < count; i++) {
140 if(((unsigned char *)indices)[i] < min)
141 min = ((unsigned char *)indices)[i];
142 if(((unsigned char *)indices)[i] > max)
143 max = ((unsigned char *)indices)[i];
144 }
145
146 elt_size = 2;
147
148 r300AllocDmaRegion(rmesa, &rvb, count * elt_size, elt_size);
149 rvb.aos_offset = GET_START(&rvb);
150 ptr = rvb.address + rvb.start;
151
152 for (i=0; i < count; i++)
153 ((unsigned short int *)ptr)[i] = ((unsigned char *)indices)[i] - min;
154 break;
155
156 case GL_UNSIGNED_SHORT:
157 for (i=0; i < count; i++) {
158 if(((unsigned short int *)indices)[i] < min)
159 min = ((unsigned short int *)indices)[i];
160 if(((unsigned short int *)indices)[i] > max)
161 max = ((unsigned short int *)indices)[i];
162 }
163
164 elt_size = 2;
165
166 r300AllocDmaRegion(rmesa, &rvb, count * elt_size, elt_size);
167 rvb.aos_offset = GET_START(&rvb);
168 ptr = rvb.address + rvb.start;
169
170 for (i=0; i < count; i++)
171 ((unsigned short int *)ptr)[i] = ((unsigned short int *)indices)[i] - min;
172 break;
173
174 case GL_UNSIGNED_INT:
175 for (i=0; i < count; i++) {
176 if(((unsigned int *)indices)[i] < min)
177 min = ((unsigned int *)indices)[i];
178 if(((unsigned int *)indices)[i] > max)
179 max = ((unsigned int *)indices)[i];
180 }
181
182 if (max - min <= 65535)
183 elt_size = 2;
184 else
185 elt_size = 4;
186
187 r300AllocDmaRegion(rmesa, &rvb, count * elt_size, elt_size);
188 rvb.aos_offset = GET_START(&rvb);
189 ptr = rvb.address + rvb.start;
190
191
192 if (max - min <= 65535)
193 for (i=0; i < count; i++)
194 ((unsigned short int *)ptr)[i] = ((unsigned int *)indices)[i] - min;
195 else
196 for (i=0; i < count; i++)
197 ((unsigned int *)ptr)[i] = ((unsigned int *)indices)[i] - min;
198 break;
199
200 default:
201 fprintf(stderr, "Unknown elt type!\n");
202 return;
203
204
205 }
206
207 if (ctx->NewState)
208 _mesa_update_state( ctx );
209
210 r300UpdateShaders(rmesa);
211
212 if (rmesa->state.VB.LockCount) {
213 if (rmesa->state.VB.lock_uptodate == GL_FALSE) {
214 if (setup_arrays(rmesa, rmesa->state.VB.LockFirst))
215 return;
216
217 rmesa->state.VB.Count = rmesa->state.VB.LockCount;
218
219 r300ReleaseArrays(ctx);
220 r300EmitArraysVtx(ctx, GL_FALSE);
221
222 rmesa->state.VB.lock_uptodate = GL_TRUE;
223 }
224
225 if (min < rmesa->state.VB.LockFirst) {
226 WARN_ONCE("Out of range min %d vs %d!\n", min, rmesa->state.VB.LockFirst);
227 return;
228 }
229
230 if (max >= rmesa->state.VB.LockFirst + rmesa->state.VB.LockCount) {
231 WARN_ONCE("Out of range max %d vs %d!\n", max, rmesa->state.VB.LockFirst +
232 rmesa->state.VB.LockCount);
233 return;
234 }
235 } else {
236 if (setup_arrays(rmesa, min))
237 return;
238 rmesa->state.VB.Count = max - min + 1;
239 }
240
241 r300UpdateShaderStates(rmesa);
242
243 rmesa->state.VB.Primitive = &prim;
244 rmesa->state.VB.PrimitiveCount = 1;
245
246 prim.mode = mode | PRIM_BEGIN | PRIM_END;
247 if (rmesa->state.VB.LockCount)
248 prim.start = min - rmesa->state.VB.LockFirst;
249 else
250 prim.start = 0;
251 prim.count = count;
252
253 rmesa->state.VB.Elts = ptr;
254 rmesa->state.VB.elt_size = elt_size;
255
256 r300_run_vb_render_vtxfmt_a(ctx, NULL);
257
258 if(rvb.buf)
259 radeon_mm_use(rmesa, rvb.buf->id);
260 }
261
262 void radeonDrawRangeElements(GLenum mode, GLuint min, GLuint max, GLsizei count, GLenum type, const GLvoid *indices)
263 {
264 GET_CURRENT_CONTEXT(ctx);
265 r300ContextPtr rmesa = R300_CONTEXT(ctx);
266 struct tnl_prim prim;
267 int elt_size;
268 int i;
269 void *ptr = NULL;
270 static struct r300_dma_region rvb;
271
272 if (ctx->Array.ElementArrayBufferObj->Name) {
273 /* use indices in the buffer object */
274 if (!ctx->Array.ElementArrayBufferObj->Data) {
275 _mesa_warning(ctx, "DrawRangeElements with empty vertex elements buffer!");
276 return;
277 }
278 /* actual address is the sum of pointers */
279 indices = (const GLvoid *)
280 ADD_POINTERS(ctx->Array.ElementArrayBufferObj->Data, (const GLubyte *) indices);
281 }
282
283 if (!_mesa_validate_DrawRangeElements( ctx, mode, min, max, count, type, indices ))
284 return;
285
286 FLUSH_CURRENT( ctx, 0 );
287 #ifdef OPTIMIZE_ELTS
288 min = 0;
289 #endif
290 r300ReleaseDmaRegion(rmesa, &rvb, __FUNCTION__);
291
292 switch(type){
293 case GL_UNSIGNED_BYTE:
294 elt_size = 2;
295
296 r300AllocDmaRegion(rmesa, &rvb, count * elt_size, elt_size);
297 rvb.aos_offset = GET_START(&rvb);
298 ptr = rvb.address + rvb.start;
299
300 for(i=0; i < count; i++)
301 ((unsigned short int *)ptr)[i] = ((unsigned char *)indices)[i] - min;
302 break;
303
304 case GL_UNSIGNED_SHORT:
305 elt_size = 2;
306
307 #ifdef OPTIMIZE_ELTS
308 if (min == 0 && ctx->Array.ElementArrayBufferObj->Name){
309 ptr = indices;
310 break;
311 }
312 #endif
313 r300AllocDmaRegion(rmesa, &rvb, count * elt_size, elt_size);
314 rvb.aos_offset = GET_START(&rvb);
315 ptr = rvb.address + rvb.start;
316
317 for(i=0; i < count; i++)
318 ((unsigned short int *)ptr)[i] = ((unsigned short int *)indices)[i] - min;
319 break;
320
321 case GL_UNSIGNED_INT:
322 if (max - min <= 65535)
323 elt_size = 2;
324 else
325 elt_size = 4;
326
327 r300AllocDmaRegion(rmesa, &rvb, count * elt_size, elt_size);
328 rvb.aos_offset = GET_START(&rvb);
329 ptr = rvb.address + rvb.start;
330
331 if (max - min <= 65535)
332 for (i=0; i < count; i++)
333 ((unsigned short int *)ptr)[i] = ((unsigned int *)indices)[i] - min;
334 else
335 for (i=0; i < count; i++)
336 ((unsigned int *)ptr)[i] = ((unsigned int *)indices)[i] - min;
337 break;
338
339 default:
340 fprintf(stderr, "Unknown elt type!\n");
341 return;
342
343 }
344
345 /* XXX: setup_arrays before state update? */
346
347 if (ctx->NewState)
348 _mesa_update_state( ctx );
349
350 r300UpdateShaders(rmesa);
351
352 if (rmesa->state.VB.LockCount) {
353 if (rmesa->state.VB.lock_uptodate == GL_FALSE) {
354 if (setup_arrays(rmesa, rmesa->state.VB.LockFirst))
355 return;
356
357 rmesa->state.VB.Count = rmesa->state.VB.LockCount;
358
359 r300ReleaseArrays(ctx);
360 r300EmitArraysVtx(ctx, GL_FALSE);
361
362 rmesa->state.VB.lock_uptodate = GL_TRUE;
363 }
364
365 if (min < rmesa->state.VB.LockFirst) {
366 WARN_ONCE("Out of range min %d vs %d!\n", min, rmesa->state.VB.LockFirst);
367 return;
368 }
369
370 /*if (max >= rmesa->state.VB.LockFirst + rmesa->state.VB.LockCount) {
371 WARN_ONCE("Out of range max %d vs %d!\n", max, rmesa->state.VB.LockFirst +
372 rmesa->state.VB.LockCount);
373 return;
374 }*/
375 } else {
376 if (setup_arrays(rmesa, min))
377 return;
378 rmesa->state.VB.Count = max - min + 1;
379 }
380
381 r300UpdateShaderStates(rmesa);
382
383 rmesa->state.VB.Primitive = &prim;
384 rmesa->state.VB.PrimitiveCount = 1;
385
386 prim.mode = mode | PRIM_BEGIN | PRIM_END;
387 if (rmesa->state.VB.LockCount)
388 prim.start = min - rmesa->state.VB.LockFirst;
389 else
390 prim.start = 0;
391 prim.count = count;
392
393 rmesa->state.VB.Elts = ptr;
394 rmesa->state.VB.elt_size = elt_size;
395 rmesa->state.VB.elt_min = min;
396 rmesa->state.VB.elt_max = max;
397
398 r300_run_vb_render_vtxfmt_a(ctx, NULL);
399
400 if(rvb.buf)
401 radeon_mm_use(rmesa, rvb.buf->id);
402 }
403
404 void radeonDrawArrays( GLenum mode, GLint start, GLsizei count )
405 {
406 GET_CURRENT_CONTEXT(ctx);
407 r300ContextPtr rmesa = R300_CONTEXT(ctx);
408 struct tnl_prim prim;
409
410 if (!_mesa_validate_DrawArrays( ctx, mode, start, count ))
411 return;
412
413 FLUSH_CURRENT( ctx, 0 );
414
415 if (ctx->NewState)
416 _mesa_update_state( ctx );
417
418 /* XXX: setup_arrays before state update? */
419
420 r300UpdateShaders(rmesa);
421
422 if (rmesa->state.VB.LockCount) {
423 if (rmesa->state.VB.lock_uptodate == GL_FALSE) {
424 if (setup_arrays(rmesa, rmesa->state.VB.LockFirst))
425 return;
426
427 rmesa->state.VB.Count = rmesa->state.VB.LockCount;
428
429 r300ReleaseArrays(ctx);
430 r300EmitArraysVtx(ctx, GL_FALSE);
431
432 rmesa->state.VB.lock_uptodate = GL_TRUE;
433 }
434
435 if (start < rmesa->state.VB.LockFirst) {
436 WARN_ONCE("Out of range min %d vs %d!\n", start, rmesa->state.VB.LockFirst);
437 return;
438 }
439
440 if (start + count - 1 >= rmesa->state.VB.LockFirst + rmesa->state.VB.LockCount) { /* XXX */
441 WARN_ONCE("Out of range max %d vs %d!\n", start + count - 1, rmesa->state.VB.LockFirst +
442 rmesa->state.VB.LockCount);
443 return;
444 }
445 } else {
446 if (setup_arrays(rmesa, start))
447 return;
448 rmesa->state.VB.Count = count;
449 }
450
451 r300UpdateShaderStates(rmesa);
452
453 rmesa->state.VB.Primitive = &prim;
454 rmesa->state.VB.PrimitiveCount = 1;
455
456 prim.mode = mode | PRIM_BEGIN | PRIM_END;
457 if (rmesa->state.VB.LockCount)
458 prim.start = start - rmesa->state.VB.LockFirst;
459 else
460 prim.start = 0;
461 prim.count = count;
462
463 rmesa->state.VB.Elts = NULL;
464 rmesa->state.VB.elt_size = 0;
465 rmesa->state.VB.elt_min = 0;
466 rmesa->state.VB.elt_max = 0;
467
468 r300_run_vb_render_vtxfmt_a(ctx, NULL);
469 }
470
471 void radeon_init_vtxfmt_a(r300ContextPtr rmesa)
472 {
473 GLcontext *ctx;
474 GLvertexformat *vfmt;
475
476 ctx = rmesa->radeon.glCtx;
477 vfmt = ctx->TnlModule.Current;
478
479 vfmt->DrawElements = radeonDrawElements;
480 vfmt->DrawArrays = radeonDrawArrays;
481 vfmt->DrawRangeElements = radeonDrawRangeElements;
482
483 }
484 #endif
485
486 #ifdef HW_VBOS
487
488 void radeonLockArraysEXT(GLcontext *ctx, GLint first, GLsizei count)
489 {
490 r300ContextPtr rmesa = R300_CONTEXT(ctx);
491 int i;
492
493 /* Only when CB_DPATH is defined.
494 r300Clear tampers over the aos setup without it.
495 (r300ResetHwState cannot call r300EmitArrays)
496 */
497 #ifndef CB_DPATH
498 first = 0; count = 0;
499 #endif
500
501 if (first < 0 || count <= 0) {
502 rmesa->state.VB.LockFirst = 0;
503 rmesa->state.VB.LockCount = 0;
504 rmesa->state.VB.lock_uptodate = GL_FALSE;
505 return ;
506 }
507
508 rmesa->state.VB.LockFirst = first;
509 rmesa->state.VB.LockCount = count;
510 rmesa->state.VB.lock_uptodate = GL_FALSE;
511 }
512
513 void radeonUnlockArraysEXT(GLcontext *ctx)
514 {
515 r300ContextPtr rmesa = R300_CONTEXT(ctx);
516
517 rmesa->state.VB.LockFirst = 0;
518 rmesa->state.VB.LockCount = 0;
519 rmesa->state.VB.lock_uptodate = GL_FALSE;
520 }
521
522 struct gl_buffer_object *
523 r300NewBufferObject(GLcontext *ctx, GLuint name, GLenum target )
524 {
525 struct r300_buffer_object *obj;
526
527 (void) ctx;
528
529 obj = MALLOC_STRUCT(r300_buffer_object);
530 _mesa_initialize_buffer_object(&obj->mesa_obj, name, target);
531 return &obj->mesa_obj;
532 }
533
534 void r300BufferData(GLcontext *ctx, GLenum target, GLsizeiptrARB size,
535 const GLvoid *data, GLenum usage, struct gl_buffer_object *obj)
536 {
537 r300ContextPtr rmesa = R300_CONTEXT(ctx);
538 struct r300_buffer_object *r300_obj = (struct r300_buffer_object *)obj;
539 drm_radeon_mem_alloc_t alloc;
540 int offset, ret;
541
542 /* Free previous buffer */
543 if (obj->OnCard) {
544 radeon_mm_free(rmesa, r300_obj->id);
545 obj->OnCard = GL_FALSE;
546 } else {
547 if (obj->Data)
548 free(obj->Data);
549 }
550 #ifdef OPTIMIZE_ELTS
551 if (0) {
552 #else
553 if (target == GL_ELEMENT_ARRAY_BUFFER_ARB) {
554 #endif
555 obj->Data = malloc(size);
556
557 if (data)
558 memcpy(obj->Data, data, size);
559
560 obj->OnCard = GL_FALSE;
561 } else {
562 r300_obj->id = radeon_mm_alloc(rmesa, 4, size);
563 obj->Data = radeon_mm_map(rmesa, r300_obj->id, RADEON_MM_W);
564
565 if (data)
566 memcpy(obj->Data, data, size);
567
568 radeon_mm_unmap(rmesa, r300_obj->id);
569 obj->OnCard = GL_TRUE;
570 }
571
572 obj->Size = size;
573 obj->Usage = usage;
574 }
575
576 void r300BufferSubData(GLcontext *ctx, GLenum target, GLintptrARB offset,
577 GLsizeiptrARB size, const GLvoid * data, struct gl_buffer_object * bufObj)
578 {
579 r300ContextPtr rmesa = R300_CONTEXT(ctx);
580 struct r300_buffer_object *r300_obj = (struct r300_buffer_object *)bufObj;
581 (void) ctx; (void) target;
582 void *ptr;
583
584 if (bufObj->Data && ((GLuint) (size + offset) <= bufObj->Size)) {
585 if (bufObj->OnCard){
586 ptr = radeon_mm_map(rmesa, r300_obj->id, RADEON_MM_W);
587
588 _mesa_memcpy( (GLubyte *) ptr + offset, data, size );
589
590 radeon_mm_unmap(rmesa, r300_obj->id);
591 } else {
592 _mesa_memcpy( (GLubyte *) bufObj->Data + offset, data, size );
593 }
594 }
595 }
596
597 void *r300MapBuffer(GLcontext *ctx, GLenum target, GLenum access,
598 struct gl_buffer_object *bufObj)
599 {
600 r300ContextPtr rmesa = R300_CONTEXT(ctx);
601 struct r300_buffer_object *r300_obj = (struct r300_buffer_object *)bufObj;
602
603 (void) ctx;
604 (void) target;
605 (void) access;
606 //ASSERT(!bufObj->OnCard);
607 /* Just return a direct pointer to the data */
608 if (bufObj->Pointer) {
609 /* already mapped! */
610 return NULL;
611 }
612
613 if (!bufObj->OnCard) {
614 bufObj->Pointer = bufObj->Data;
615 return bufObj->Pointer;
616 }
617
618 switch (access) {
619 case GL_READ_ONLY:
620 bufObj->Pointer = radeon_mm_map(rmesa, r300_obj->id, RADEON_MM_R);
621 break;
622
623 case GL_WRITE_ONLY:
624 bufObj->Pointer = radeon_mm_map(rmesa, r300_obj->id, RADEON_MM_W);
625 break;
626
627 case GL_READ_WRITE:
628 bufObj->Pointer = radeon_mm_map(rmesa, r300_obj->id, RADEON_MM_RW);
629 break;
630
631 default:
632 WARN_ONCE("Unknown access type\n");
633 bufObj->Pointer = NULL;
634 break;
635 }
636
637 return bufObj->Pointer;
638 }
639
640 GLboolean r300UnmapBuffer(GLcontext *ctx, GLenum target, struct gl_buffer_object *bufObj)
641 {
642 r300ContextPtr rmesa = R300_CONTEXT(ctx);
643 struct r300_buffer_object *r300_obj = (struct r300_buffer_object *)bufObj;
644
645 (void) ctx;
646 (void) target;
647 //ASSERT(!bufObj->OnCard);
648 /* XXX we might assert here that bufObj->Pointer is non-null */
649 if (!bufObj->OnCard) {
650 bufObj->Pointer = NULL;
651 return GL_TRUE;
652 }
653 radeon_mm_unmap(rmesa, r300_obj->id);
654
655 bufObj->Pointer = NULL;
656 return GL_TRUE;
657 }
658
659 void r300DeleteBuffer(GLcontext *ctx, struct gl_buffer_object *obj)
660 {
661 r300ContextPtr rmesa = R300_CONTEXT(ctx);
662 struct r300_buffer_object *r300_obj = (struct r300_buffer_object *)obj;
663
664 if (obj->OnCard) {
665 radeon_mm_free(rmesa, r300_obj->id);
666 obj->Data = NULL;
667 }
668 _mesa_delete_buffer_object(ctx, obj);
669 }
670
671 void r300_init_vbo_funcs(struct dd_function_table *functions)
672 {
673 functions->NewBufferObject = r300NewBufferObject;
674 functions->BufferData = r300BufferData;
675 functions->BufferSubData = r300BufferSubData;
676 functions->MapBuffer = r300MapBuffer;
677 functions->UnmapBuffer = r300UnmapBuffer;
678 functions->DeleteBuffer = r300DeleteBuffer;
679
680 functions->LockArraysEXT = radeonLockArraysEXT;
681 functions->UnlockArraysEXT = radeonUnlockArraysEXT;
682 }
683
684 #endif