mesa: restore glapi/ prefix on #include
[mesa.git] / src / mesa / drivers / dri / intel / intel_fbo.c
1 /**************************************************************************
2 *
3 * Copyright 2006 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * 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
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28
29 #include "main/imports.h"
30 #include "main/mtypes.h"
31 #include "main/fbobject.h"
32 #include "main/framebuffer.h"
33 #include "main/renderbuffer.h"
34 #include "main/context.h"
35 #include "main/texformat.h"
36 #include "main/texrender.h"
37
38 #include "intel_context.h"
39 #include "intel_buffers.h"
40 #include "intel_depthstencil.h"
41 #include "intel_fbo.h"
42 #include "intel_mipmap_tree.h"
43 #include "intel_regions.h"
44 #include "intel_span.h"
45
46
47 #define FILE_DEBUG_FLAG DEBUG_FBO
48
49 #define INTEL_RB_CLASS 0x12345678
50
51
52 /* XXX FBO: move this to intel_context.h (inlined) */
53 /**
54 * Return a gl_renderbuffer ptr casted to intel_renderbuffer.
55 * NULL will be returned if the rb isn't really an intel_renderbuffer.
56 * This is determiend by checking the ClassID.
57 */
58 struct intel_renderbuffer *
59 intel_renderbuffer(struct gl_renderbuffer *rb)
60 {
61 struct intel_renderbuffer *irb = (struct intel_renderbuffer *) rb;
62 if (irb && irb->Base.ClassID == INTEL_RB_CLASS) {
63 /*_mesa_warning(NULL, "Returning non-intel Rb\n");*/
64 return irb;
65 }
66 else
67 return NULL;
68 }
69
70
71 struct intel_renderbuffer *
72 intel_get_renderbuffer(struct gl_framebuffer *fb, int attIndex)
73 {
74 if (attIndex >= 0)
75 return intel_renderbuffer(fb->Attachment[attIndex].Renderbuffer);
76 else
77 return NULL;
78 }
79
80
81 void
82 intel_flip_renderbuffers(struct intel_framebuffer *intel_fb)
83 {
84 int current_page = intel_fb->pf_current_page;
85 int next_page = (current_page + 1) % intel_fb->pf_num_pages;
86 struct gl_renderbuffer *tmp_rb;
87
88 /* Exchange renderbuffers if necessary but make sure their reference counts
89 * are preserved.
90 */
91 if (intel_fb->color_rb[current_page] &&
92 intel_fb->Base.Attachment[BUFFER_FRONT_LEFT].Renderbuffer !=
93 &intel_fb->color_rb[current_page]->Base) {
94 tmp_rb = NULL;
95 _mesa_reference_renderbuffer(&tmp_rb,
96 intel_fb->Base.Attachment[BUFFER_FRONT_LEFT].Renderbuffer);
97 tmp_rb = &intel_fb->color_rb[current_page]->Base;
98 _mesa_reference_renderbuffer(
99 &intel_fb->Base.Attachment[BUFFER_FRONT_LEFT].Renderbuffer, tmp_rb);
100 _mesa_reference_renderbuffer(&tmp_rb, NULL);
101 }
102
103 if (intel_fb->color_rb[next_page] &&
104 intel_fb->Base.Attachment[BUFFER_BACK_LEFT].Renderbuffer !=
105 &intel_fb->color_rb[next_page]->Base) {
106 tmp_rb = NULL;
107 _mesa_reference_renderbuffer(&tmp_rb,
108 intel_fb->Base.Attachment[BUFFER_BACK_LEFT].Renderbuffer);
109 tmp_rb = &intel_fb->color_rb[next_page]->Base;
110 _mesa_reference_renderbuffer(
111 &intel_fb->Base.Attachment[BUFFER_BACK_LEFT].Renderbuffer, tmp_rb);
112 _mesa_reference_renderbuffer(&tmp_rb, NULL);
113 }
114 }
115
116
117 struct intel_region *
118 intel_get_rb_region(struct gl_framebuffer *fb, GLuint attIndex)
119 {
120 struct intel_renderbuffer *irb = intel_get_renderbuffer(fb, attIndex);
121
122 if (irb)
123 return irb->region;
124 else
125 return NULL;
126 }
127
128
129
130 /**
131 * Create a new framebuffer object.
132 */
133 static struct gl_framebuffer *
134 intel_new_framebuffer(GLcontext * ctx, GLuint name)
135 {
136 /* Only drawable state in intel_framebuffer at this time, just use Mesa's
137 * class
138 */
139 return _mesa_new_framebuffer(ctx, name);
140 }
141
142
143 static void
144 intel_delete_renderbuffer(struct gl_renderbuffer *rb)
145 {
146 GET_CURRENT_CONTEXT(ctx);
147 struct intel_context *intel = intel_context(ctx);
148 struct intel_renderbuffer *irb = intel_renderbuffer(rb);
149
150 ASSERT(irb);
151
152 if (irb->PairedStencil || irb->PairedDepth) {
153 intel_unpair_depth_stencil(ctx, irb);
154 }
155
156 if (irb->span_cache != NULL)
157 _mesa_free(irb->span_cache);
158
159 if (intel && irb->region) {
160 intel_region_release(&irb->region);
161 }
162
163 _mesa_free(irb);
164 }
165
166
167
168 /**
169 * Return a pointer to a specific pixel in a renderbuffer.
170 */
171 static void *
172 intel_get_pointer(GLcontext * ctx, struct gl_renderbuffer *rb,
173 GLint x, GLint y)
174 {
175 /* By returning NULL we force all software rendering to go through
176 * the span routines.
177 */
178 return NULL;
179 }
180
181
182
183 /**
184 * Called via glRenderbufferStorageEXT() to set the format and allocate
185 * storage for a user-created renderbuffer.
186 */
187 static GLboolean
188 intel_alloc_renderbuffer_storage(GLcontext * ctx, struct gl_renderbuffer *rb,
189 GLenum internalFormat,
190 GLuint width, GLuint height)
191 {
192 struct intel_context *intel = intel_context(ctx);
193 struct intel_renderbuffer *irb = intel_renderbuffer(rb);
194 GLboolean softwareBuffer = GL_FALSE;
195 int cpp;
196
197 ASSERT(rb->Name != 0);
198
199 switch (internalFormat) {
200 case GL_R3_G3_B2:
201 case GL_RGB4:
202 case GL_RGB5:
203 rb->_ActualFormat = GL_RGB5;
204 rb->DataType = GL_UNSIGNED_BYTE;
205 rb->RedBits = 5;
206 rb->GreenBits = 6;
207 rb->BlueBits = 5;
208 cpp = 2;
209 break;
210 case GL_RGB:
211 case GL_RGB8:
212 case GL_RGB10:
213 case GL_RGB12:
214 case GL_RGB16:
215 rb->_ActualFormat = GL_RGB8;
216 rb->DataType = GL_UNSIGNED_BYTE;
217 rb->RedBits = 8;
218 rb->GreenBits = 8;
219 rb->BlueBits = 8;
220 rb->AlphaBits = 0;
221 cpp = 4;
222 break;
223 case GL_RGBA:
224 case GL_RGBA2:
225 case GL_RGBA4:
226 case GL_RGB5_A1:
227 case GL_RGBA8:
228 case GL_RGB10_A2:
229 case GL_RGBA12:
230 case GL_RGBA16:
231 rb->_ActualFormat = GL_RGBA8;
232 rb->DataType = GL_UNSIGNED_BYTE;
233 rb->RedBits = 8;
234 rb->GreenBits = 8;
235 rb->BlueBits = 8;
236 rb->AlphaBits = 8;
237 cpp = 4;
238 break;
239 case GL_STENCIL_INDEX:
240 case GL_STENCIL_INDEX1_EXT:
241 case GL_STENCIL_INDEX4_EXT:
242 case GL_STENCIL_INDEX8_EXT:
243 case GL_STENCIL_INDEX16_EXT:
244 /* alloc a depth+stencil buffer */
245 rb->_ActualFormat = GL_DEPTH24_STENCIL8_EXT;
246 rb->DataType = GL_UNSIGNED_INT_24_8_EXT;
247 rb->StencilBits = 8;
248 cpp = 4;
249 break;
250 case GL_DEPTH_COMPONENT16:
251 rb->_ActualFormat = GL_DEPTH_COMPONENT16;
252 rb->DataType = GL_UNSIGNED_SHORT;
253 rb->DepthBits = 16;
254 cpp = 2;
255 break;
256 case GL_DEPTH_COMPONENT:
257 case GL_DEPTH_COMPONENT24:
258 case GL_DEPTH_COMPONENT32:
259 rb->_ActualFormat = GL_DEPTH24_STENCIL8_EXT;
260 rb->DataType = GL_UNSIGNED_INT_24_8_EXT;
261 rb->DepthBits = 24;
262 cpp = 4;
263 break;
264 case GL_DEPTH_STENCIL_EXT:
265 case GL_DEPTH24_STENCIL8_EXT:
266 rb->_ActualFormat = GL_DEPTH24_STENCIL8_EXT;
267 rb->DataType = GL_UNSIGNED_INT_24_8_EXT;
268 rb->DepthBits = 24;
269 rb->StencilBits = 8;
270 cpp = 4;
271 break;
272 default:
273 _mesa_problem(ctx,
274 "Unexpected format in intel_alloc_renderbuffer_storage");
275 return GL_FALSE;
276 }
277
278 intelFlush(ctx);
279
280 /* free old region */
281 if (irb->region) {
282 intel_region_release(&irb->region);
283 }
284
285 /* allocate new memory region/renderbuffer */
286 if (softwareBuffer) {
287 return _mesa_soft_renderbuffer_storage(ctx, rb, internalFormat,
288 width, height);
289 }
290 else {
291 /* Choose a pitch to match hardware requirements:
292 */
293 GLuint pitch = ((cpp * width + 63) & ~63) / cpp;
294
295 /* alloc hardware renderbuffer */
296 DBG("Allocating %d x %d Intel RBO (pitch %d)\n", width,
297 height, pitch);
298
299 irb->region = intel_region_alloc(intel, cpp, width, height, pitch);
300 if (!irb->region)
301 return GL_FALSE; /* out of memory? */
302
303 ASSERT(irb->region->buffer);
304
305 rb->Width = width;
306 rb->Height = height;
307
308 return GL_TRUE;
309 }
310 }
311
312
313
314 /**
315 * Called for each hardware renderbuffer when a _window_ is resized.
316 * Just update fields.
317 * Not used for user-created renderbuffers!
318 */
319 static GLboolean
320 intel_alloc_window_storage(GLcontext * ctx, struct gl_renderbuffer *rb,
321 GLenum internalFormat, GLuint width, GLuint height)
322 {
323 ASSERT(rb->Name == 0);
324 rb->Width = width;
325 rb->Height = height;
326 rb->_ActualFormat = internalFormat;
327
328 return GL_TRUE;
329 }
330
331 static void
332 intel_resize_buffers(GLcontext *ctx, struct gl_framebuffer *fb,
333 GLuint width, GLuint height)
334 {
335 struct intel_framebuffer *intel_fb = (struct intel_framebuffer*)fb;
336 int i;
337
338 _mesa_resize_framebuffer(ctx, fb, width, height);
339
340 fb->Initialized = GL_TRUE; /* XXX remove someday */
341
342 if (fb->Name != 0) {
343 return;
344 }
345
346 /* Make sure all window system renderbuffers are up to date */
347 for (i = 0; i < 3; i++) {
348 struct gl_renderbuffer *rb = &intel_fb->color_rb[i]->Base;
349
350 /* only resize if size is changing */
351 if (rb && (rb->Width != width || rb->Height != height)) {
352 rb->AllocStorage(ctx, rb, rb->InternalFormat, width, height);
353 }
354 }
355 }
356
357 static GLboolean
358 intel_nop_alloc_storage(GLcontext * ctx, struct gl_renderbuffer *rb,
359 GLenum internalFormat, GLuint width, GLuint height)
360 {
361 _mesa_problem(ctx, "intel_op_alloc_storage should never be called.");
362 return GL_FALSE;
363 }
364
365
366 void
367 intel_renderbuffer_set_region(struct intel_renderbuffer *rb,
368 struct intel_region *region)
369 {
370 struct intel_region *old;
371
372 old = rb->region;
373 rb->region = NULL;
374 intel_region_reference(&rb->region, region);
375 intel_region_release(&old);
376
377 rb->pfPitch = region->pitch;
378 }
379
380 /**
381 * Create a new intel_renderbuffer which corresponds to an on-screen window,
382 * not a user-created renderbuffer.
383 */
384 struct intel_renderbuffer *
385 intel_create_renderbuffer(GLenum intFormat)
386 {
387 GET_CURRENT_CONTEXT(ctx);
388
389 struct intel_renderbuffer *irb;
390 const GLuint name = 0;
391
392 irb = CALLOC_STRUCT(intel_renderbuffer);
393 if (!irb) {
394 _mesa_error(ctx, GL_OUT_OF_MEMORY, "creating renderbuffer");
395 return NULL;
396 }
397
398 _mesa_init_renderbuffer(&irb->Base, name);
399 irb->Base.ClassID = INTEL_RB_CLASS;
400
401 switch (intFormat) {
402 case GL_RGB5:
403 irb->Base._ActualFormat = GL_RGB5;
404 irb->Base._BaseFormat = GL_RGBA;
405 irb->Base.RedBits = 5;
406 irb->Base.GreenBits = 6;
407 irb->Base.BlueBits = 5;
408 irb->Base.DataType = GL_UNSIGNED_BYTE;
409 break;
410 case GL_RGBA8:
411 irb->Base._ActualFormat = GL_RGBA8;
412 irb->Base._BaseFormat = GL_RGBA;
413 irb->Base.RedBits = 8;
414 irb->Base.GreenBits = 8;
415 irb->Base.BlueBits = 8;
416 irb->Base.AlphaBits = 8;
417 irb->Base.DataType = GL_UNSIGNED_BYTE;
418 break;
419 case GL_STENCIL_INDEX8_EXT:
420 irb->Base._ActualFormat = GL_STENCIL_INDEX8_EXT;
421 irb->Base._BaseFormat = GL_STENCIL_INDEX;
422 irb->Base.StencilBits = 8;
423 irb->Base.DataType = GL_UNSIGNED_BYTE;
424 break;
425 case GL_DEPTH_COMPONENT16:
426 irb->Base._ActualFormat = GL_DEPTH_COMPONENT16;
427 irb->Base._BaseFormat = GL_DEPTH_COMPONENT;
428 irb->Base.DepthBits = 16;
429 irb->Base.DataType = GL_UNSIGNED_SHORT;
430 break;
431 case GL_DEPTH_COMPONENT24:
432 irb->Base._ActualFormat = GL_DEPTH24_STENCIL8_EXT;
433 irb->Base._BaseFormat = GL_DEPTH_COMPONENT;
434 irb->Base.DepthBits = 24;
435 irb->Base.DataType = GL_UNSIGNED_INT;
436 break;
437 case GL_DEPTH24_STENCIL8_EXT:
438 irb->Base._ActualFormat = GL_DEPTH24_STENCIL8_EXT;
439 irb->Base._BaseFormat = GL_DEPTH_STENCIL_EXT;
440 irb->Base.DepthBits = 24;
441 irb->Base.StencilBits = 8;
442 irb->Base.DataType = GL_UNSIGNED_INT_24_8_EXT;
443 break;
444 default:
445 _mesa_problem(NULL,
446 "Unexpected intFormat in intel_create_renderbuffer");
447 return NULL;
448 }
449
450 irb->Base.InternalFormat = intFormat;
451
452 /* intel-specific methods */
453 irb->Base.Delete = intel_delete_renderbuffer;
454 irb->Base.AllocStorage = intel_alloc_window_storage;
455 irb->Base.GetPointer = intel_get_pointer;
456
457 return irb;
458 }
459
460
461 /**
462 * Create a new renderbuffer object.
463 * Typically called via glBindRenderbufferEXT().
464 */
465 static struct gl_renderbuffer *
466 intel_new_renderbuffer(GLcontext * ctx, GLuint name)
467 {
468 /*struct intel_context *intel = intel_context(ctx); */
469 struct intel_renderbuffer *irb;
470
471 irb = CALLOC_STRUCT(intel_renderbuffer);
472 if (!irb) {
473 _mesa_error(ctx, GL_OUT_OF_MEMORY, "creating renderbuffer");
474 return NULL;
475 }
476
477 _mesa_init_renderbuffer(&irb->Base, name);
478 irb->Base.ClassID = INTEL_RB_CLASS;
479
480 /* intel-specific methods */
481 irb->Base.Delete = intel_delete_renderbuffer;
482 irb->Base.AllocStorage = intel_alloc_renderbuffer_storage;
483 irb->Base.GetPointer = intel_get_pointer;
484 /* span routines set in alloc_storage function */
485
486 return &irb->Base;
487 }
488
489
490 /**
491 * Called via glBindFramebufferEXT().
492 */
493 static void
494 intel_bind_framebuffer(GLcontext * ctx, GLenum target,
495 struct gl_framebuffer *fb, struct gl_framebuffer *fbread)
496 {
497 if (target == GL_FRAMEBUFFER_EXT || target == GL_DRAW_FRAMEBUFFER_EXT) {
498 intel_draw_buffer(ctx, fb);
499 /* Integer depth range depends on depth buffer bits */
500 if (ctx->Driver.DepthRange != NULL)
501 ctx->Driver.DepthRange(ctx, ctx->Viewport.Near, ctx->Viewport.Far);
502 }
503 else {
504 /* don't need to do anything if target == GL_READ_FRAMEBUFFER_EXT */
505 }
506 }
507
508
509 /**
510 * Called via glFramebufferRenderbufferEXT().
511 */
512 static void
513 intel_framebuffer_renderbuffer(GLcontext * ctx,
514 struct gl_framebuffer *fb,
515 GLenum attachment, struct gl_renderbuffer *rb)
516 {
517 DBG("Intel FramebufferRenderbuffer %u %u\n", fb->Name, rb ? rb->Name : 0);
518
519 intelFlush(ctx);
520
521 _mesa_framebuffer_renderbuffer(ctx, fb, attachment, rb);
522 intel_draw_buffer(ctx, fb);
523 }
524
525 static GLboolean
526 intel_update_wrapper(GLcontext *ctx, struct intel_renderbuffer *irb,
527 struct gl_texture_image *texImage)
528 {
529 if (texImage->TexFormat == &_mesa_texformat_argb8888) {
530 irb->Base._ActualFormat = GL_RGBA8;
531 irb->Base._BaseFormat = GL_RGBA;
532 DBG("Render to RGBA8 texture OK\n");
533 }
534 else if (texImage->TexFormat == &_mesa_texformat_rgb565) {
535 irb->Base._ActualFormat = GL_RGB5;
536 irb->Base._BaseFormat = GL_RGB;
537 DBG("Render to RGB5 texture OK\n");
538 }
539 else if (texImage->TexFormat == &_mesa_texformat_z16) {
540 irb->Base._ActualFormat = GL_DEPTH_COMPONENT16;
541 irb->Base._BaseFormat = GL_DEPTH_COMPONENT;
542 DBG("Render to DEPTH16 texture OK\n");
543 } else if (texImage->TexFormat == &_mesa_texformat_s8_z24) {
544 irb->Base._ActualFormat = GL_DEPTH24_STENCIL8_EXT;
545 irb->Base._BaseFormat = GL_DEPTH_STENCIL_EXT;
546 DBG("Render to DEPTH_STENCIL texture OK\n");
547 }
548 else {
549 DBG("Render to texture BAD FORMAT %d\n",
550 texImage->TexFormat->MesaFormat);
551 return GL_FALSE;
552 }
553
554 irb->Base.InternalFormat = irb->Base._ActualFormat;
555 irb->Base.Width = texImage->Width;
556 irb->Base.Height = texImage->Height;
557 irb->Base.DataType = GL_UNSIGNED_BYTE; /* FBO XXX fix */
558 irb->Base.RedBits = texImage->TexFormat->RedBits;
559 irb->Base.GreenBits = texImage->TexFormat->GreenBits;
560 irb->Base.BlueBits = texImage->TexFormat->BlueBits;
561 irb->Base.AlphaBits = texImage->TexFormat->AlphaBits;
562 irb->Base.DepthBits = texImage->TexFormat->DepthBits;
563
564 irb->Base.Delete = intel_delete_renderbuffer;
565 irb->Base.AllocStorage = intel_nop_alloc_storage;
566
567 irb->RenderToTexture = GL_TRUE;
568
569 return GL_TRUE;
570 }
571
572 /**
573 * When glFramebufferTexture[123]D is called this function sets up the
574 * gl_renderbuffer wrapper around the texture image.
575 * This will have the region info needed for hardware rendering.
576 */
577 static struct intel_renderbuffer *
578 intel_wrap_texture(GLcontext * ctx, struct gl_texture_image *texImage)
579 {
580 const GLuint name = ~0; /* not significant, but distinct for debugging */
581 struct intel_renderbuffer *irb;
582
583 /* make an intel_renderbuffer to wrap the texture image */
584 irb = CALLOC_STRUCT(intel_renderbuffer);
585 if (!irb) {
586 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glFramebufferTexture");
587 return NULL;
588 }
589
590 _mesa_init_renderbuffer(&irb->Base, name);
591 irb->Base.ClassID = INTEL_RB_CLASS;
592
593 if (!intel_update_wrapper(ctx, irb, texImage)) {
594 _mesa_free(irb);
595 return NULL;
596 }
597
598 return irb;
599 }
600
601
602 /**
603 * Called by glFramebufferTexture[123]DEXT() (and other places) to
604 * prepare for rendering into texture memory. This might be called
605 * many times to choose different texture levels, cube faces, etc
606 * before intel_finish_render_texture() is ever called.
607 */
608 static void
609 intel_render_texture(GLcontext * ctx,
610 struct gl_framebuffer *fb,
611 struct gl_renderbuffer_attachment *att)
612 {
613 struct gl_texture_image *newImage
614 = att->Texture->Image[att->CubeMapFace][att->TextureLevel];
615 struct intel_renderbuffer *irb = intel_renderbuffer(att->Renderbuffer);
616 struct intel_texture_image *intel_image;
617 GLuint imageOffset;
618
619 (void) fb;
620
621 ASSERT(newImage);
622
623 if (!irb) {
624 irb = intel_wrap_texture(ctx, newImage);
625 if (irb) {
626 /* bind the wrapper to the attachment point */
627 _mesa_reference_renderbuffer(&att->Renderbuffer, &irb->Base);
628 }
629 else {
630 /* fallback to software rendering */
631 _mesa_render_texture(ctx, fb, att);
632 return;
633 }
634 } if (!intel_update_wrapper(ctx, irb, newImage)) {
635 _mesa_reference_renderbuffer(&att->Renderbuffer, NULL);
636 _mesa_render_texture(ctx, fb, att);
637 return;
638 }
639
640 DBG("Begin render texture tid %x tex=%u w=%d h=%d refcount=%d\n",
641 _glthread_GetID(),
642 att->Texture->Name, newImage->Width, newImage->Height,
643 irb->Base.RefCount);
644
645 /* point the renderbufer's region to the texture image region */
646 intel_image = intel_texture_image(newImage);
647 if (irb->region != intel_image->mt->region) {
648 if (irb->region)
649 intel_region_release(&irb->region);
650 intel_region_reference(&irb->region, intel_image->mt->region);
651 }
652
653 /* compute offset of the particular 2D image within the texture region */
654 imageOffset = intel_miptree_image_offset(intel_image->mt,
655 att->CubeMapFace,
656 att->TextureLevel);
657
658 if (att->Texture->Target == GL_TEXTURE_3D) {
659 const GLuint *offsets = intel_miptree_depth_offsets(intel_image->mt,
660 att->TextureLevel);
661 imageOffset += offsets[att->Zoffset];
662 }
663
664 /* store that offset in the region */
665 intel_image->mt->region->draw_offset = imageOffset;
666
667 /* update drawing region, etc */
668 intel_draw_buffer(ctx, fb);
669 }
670
671
672 /**
673 * Called by Mesa when rendering to a texture is done.
674 */
675 static void
676 intel_finish_render_texture(GLcontext * ctx,
677 struct gl_renderbuffer_attachment *att)
678 {
679 struct intel_renderbuffer *irb = intel_renderbuffer(att->Renderbuffer);
680
681 DBG("End render texture (tid %x) tex %u\n", _glthread_GetID(), att->Texture->Name);
682
683 if (irb) {
684 /* just release the region */
685 intel_region_release(&irb->region);
686 }
687 else if (att->Renderbuffer) {
688 /* software fallback */
689 _mesa_finish_render_texture(ctx, att);
690 /* XXX FBO: Need to unmap the buffer (or in intelSpanRenderStart???) */
691 }
692 }
693
694
695 /**
696 * Do one-time context initializations related to GL_EXT_framebuffer_object.
697 * Hook in device driver functions.
698 */
699 void
700 intel_fbo_init(struct intel_context *intel)
701 {
702 intel->ctx.Driver.NewFramebuffer = intel_new_framebuffer;
703 intel->ctx.Driver.NewRenderbuffer = intel_new_renderbuffer;
704 intel->ctx.Driver.BindFramebuffer = intel_bind_framebuffer;
705 intel->ctx.Driver.FramebufferRenderbuffer = intel_framebuffer_renderbuffer;
706 intel->ctx.Driver.RenderTexture = intel_render_texture;
707 intel->ctx.Driver.FinishRenderTexture = intel_finish_render_texture;
708 intel->ctx.Driver.ResizeBuffers = intel_resize_buffers;
709 }